Skip to content

Loading…

[DDC-2172] Fix EntityGenerator get literal type #526

Merged
merged 3 commits into from

3 participants

@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2174

@guilhermeblanco guilhermeblanco commented on an outdated diff
lib/Doctrine/ORM/Tools/EntityGenerator.php
((11 lines not shown))
- switch ($type) {
- case ClassMetadataInfo::INHERITANCE_TYPE_NONE:
- return 'NONE';
-
- case ClassMetadataInfo::INHERITANCE_TYPE_JOINED:
- return 'JOINED';
-
- case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE:
- return 'SINGLE_TABLE';
-
- case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS:
- return 'PER_CLASS';
-
- default:
- throw new \InvalidArgumentException('Invalid provided InheritanceType: ' . $type);
+ if( ! isset(self::$inheritanceTypeMap[$type])) {
@guilhermeblanco Doctrine member

Missing space between if and (.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco commented on an outdated diff
lib/Doctrine/ORM/Tools/EntityGenerator.php
((40 lines not shown))
{
- switch ($policy) {
- case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT:
- return 'DEFERRED_IMPLICIT';
-
- case ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT:
- return 'DEFERRED_EXPLICIT';
-
- case ClassMetadataInfo::CHANGETRACKING_NOTIFY:
- return 'NOTIFY';
-
- default:
- throw new \InvalidArgumentException('Invalid provided ChangeTrackingPolicy: ' . $policy);
+ if( ! isset(self::$changeTrackingPolicyMap[$type])) {
@guilhermeblanco Doctrine member

And here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco commented on an outdated diff
lib/Doctrine/ORM/Tools/EntityGenerator.php
((70 lines not shown))
-
- case ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE:
- return 'SEQUENCE';
-
- case ClassMetadataInfo::GENERATOR_TYPE_TABLE:
- return 'TABLE';
-
- case ClassMetadataInfo::GENERATOR_TYPE_IDENTITY:
- return 'IDENTITY';
-
- case ClassMetadataInfo::GENERATOR_TYPE_NONE:
- return 'NONE';
-
- default:
- throw new \InvalidArgumentException('Invalid provided IdGeneratorType: ' . $type);
+ if( ! isset(self::$generatorStrategyMap[$type])) {
@guilhermeblanco Doctrine member

Also here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco
Doctrine member

Very minor updates and I'm fine to merge

@FabioBatSilva
Doctrine member

Done !!!

Thanks @guilhermeblanco

@guilhermeblanco guilhermeblanco merged commit 29f0b67 into doctrine:master

1 check passed

Details default The Travis build passed
@FabioBatSilva FabioBatSilva deleted the FabioBatSilva:DDC-2172 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 27, 2012
  1. @FabioBatSilva

    Fix DDC-2172

    FabioBatSilva committed
  2. @FabioBatSilva

    refactoring tests

    FabioBatSilva committed
  3. @FabioBatSilva

    Fix CS

    FabioBatSilva committed
This page is out of date. Refresh to see the latest.
Showing with 141 additions and 46 deletions.
  1. +60 −46 lib/Doctrine/ORM/Tools/EntityGenerator.php
  2. +81 −0 tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
View
106 lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -158,6 +158,38 @@ class EntityGenerator
);
/**
+ * @var array Hash-map to handle generator types string.
+ */
+ protected static $generatorStrategyMap = array(
+ ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO',
+ ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE',
+ ClassMetadataInfo::GENERATOR_TYPE_TABLE => 'TABLE',
+ ClassMetadataInfo::GENERATOR_TYPE_IDENTITY => 'IDENTITY',
+ ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE',
+ ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID',
+ ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM'
+ );
+
+ /**
+ * @var array Hash-map to handle the change tracking policy string.
+ */
+ protected static $changeTrackingPolicyMap = array(
+ ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT',
+ ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT',
+ ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY',
+ );
+
+ /**
+ * @var array Hash-map to handle the inheritance type string.
+ */
+ protected static $inheritanceTypeMap = array(
+ ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE',
+ ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED',
+ ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE',
+ ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS',
+ );
+
+ /**
* @var string
*/
protected static $classTemplate =
@@ -1226,63 +1258,45 @@ protected function prefixCodeWithSpaces($code, $num = 1)
return implode("\n", $lines);
}
+ /**
+ * @param integer $type The inheritance type used by the class and it's subclasses.
+ * @return string The literal string for the inheritance type.
+ * @throws \InvalidArgumentException When the inheritance type does not exists.
+ */
protected function getInheritanceTypeString($type)
{
- switch ($type) {
- case ClassMetadataInfo::INHERITANCE_TYPE_NONE:
- return 'NONE';
-
- case ClassMetadataInfo::INHERITANCE_TYPE_JOINED:
- return 'JOINED';
-
- case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE:
- return 'SINGLE_TABLE';
-
- case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS:
- return 'PER_CLASS';
-
- default:
- throw new \InvalidArgumentException('Invalid provided InheritanceType: ' . $type);
+ if ( ! isset(self::$inheritanceTypeMap[$type])) {
+ throw new \InvalidArgumentException(sprintf('Invalid provided InheritanceType: %s', $type));
}
+
+ return self::$inheritanceTypeMap[$type];
}
- protected function getChangeTrackingPolicyString($policy)
+ /**
+ * @param integer $type The policy used for change-tracking for the mapped class.
+ * @return string The literal string for the change-tracking type.
+ * @throws \InvalidArgumentException When the change-tracking type does not exists.
+ */
+ protected function getChangeTrackingPolicyString($type)
{
- switch ($policy) {
- case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT:
- return 'DEFERRED_IMPLICIT';
-
- case ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT:
- return 'DEFERRED_EXPLICIT';
-
- case ClassMetadataInfo::CHANGETRACKING_NOTIFY:
- return 'NOTIFY';
-
- default:
- throw new \InvalidArgumentException('Invalid provided ChangeTrackingPolicy: ' . $policy);
+ if ( ! isset(self::$changeTrackingPolicyMap[$type])) {
+ throw new \InvalidArgumentException(sprintf('Invalid provided ChangeTrackingPolicy: %s', $type));
}
+
+ return self::$changeTrackingPolicyMap[$type];
}
+ /**
+ * @param integer $type The generator to use for the mapped class.
+ * @return string The literal string for the generetor type.
+ * @throws \InvalidArgumentException When the generator type does not exists.
+ */
protected function getIdGeneratorTypeString($type)
{
- switch ($type) {
- case ClassMetadataInfo::GENERATOR_TYPE_AUTO:
- return 'AUTO';
-
- case ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE:
- return 'SEQUENCE';
-
- case ClassMetadataInfo::GENERATOR_TYPE_TABLE:
- return 'TABLE';
-
- case ClassMetadataInfo::GENERATOR_TYPE_IDENTITY:
- return 'IDENTITY';
-
- case ClassMetadataInfo::GENERATOR_TYPE_NONE:
- return 'NONE';
-
- default:
- throw new \InvalidArgumentException('Invalid provided IdGeneratorType: ' . $type);
+ if ( ! isset(self::$generatorStrategyMap[$type])) {
+ throw new \InvalidArgumentException(sprintf('Invalid provided IdGeneratorType: %s', $type));
}
+
+ return self::$generatorStrategyMap[$type];
}
}
View
81 tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
@@ -340,6 +340,87 @@ public function testGenerateEntityWithMultipleInverseJoinColumns()
}
+ /**
+ * @group DDC-2172
+ */
+ public function testGetInheritanceTypeString()
+ {
+ $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
+ $method = new \ReflectionMethod($this->_generator, 'getInheritanceTypeString');
+ $constants = $reflection->getConstants();
+ $pattern = '/^INHERITANCE_TYPE_/';
+
+ $method->setAccessible(true);
+
+ foreach ($constants as $name => $value) {
+ if( ! preg_match($pattern, $name)) {
+ continue;
+ }
+
+ $expected = preg_replace($pattern, '', $name);
+ $actual = $method->invoke($this->_generator, $value);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ $this->setExpectedException('\InvalidArgumentException', 'Invalid provided InheritanceType: INVALID');
+ $method->invoke($this->_generator, 'INVALID');
+ }
+
+ /**
+ * @group DDC-2172
+ */
+ public function testGetChangeTrackingPolicyString()
+ {
+ $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
+ $method = new \ReflectionMethod($this->_generator, 'getChangeTrackingPolicyString');
+ $constants = $reflection->getConstants();
+ $pattern = '/^CHANGETRACKING_/';
+
+ $method->setAccessible(true);
+
+ foreach ($constants as $name => $value) {
+ if( ! preg_match($pattern, $name)) {
+ continue;
+ }
+
+ $expected = preg_replace($pattern, '', $name);
+ $actual = $method->invoke($this->_generator, $value);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ $this->setExpectedException('\InvalidArgumentException', 'Invalid provided ChangeTrackingPolicy: INVALID');
+ $method->invoke($this->_generator, 'INVALID');
+ }
+
+ /**
+ * @group DDC-2172
+ */
+ public function testGetIdGeneratorTypeString()
+ {
+ $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
+ $method = new \ReflectionMethod($this->_generator, 'getIdGeneratorTypeString');
+ $constants = $reflection->getConstants();
+ $pattern = '/^GENERATOR_TYPE_/';
+
+ $method->setAccessible(true);
+
+ foreach ($constants as $name => $value) {
+ if( ! preg_match($pattern, $name)) {
+ continue;
+ }
+
+ $expected = preg_replace($pattern, '', $name);
+ $actual = $method->invoke($this->_generator, $value);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ $this->setExpectedException('\InvalidArgumentException', 'Invalid provided IdGeneratorType: INVALID');
+ $method->invoke($this->_generator, 'INVALID');
+ }
+
/**
* @dataProvider getEntityTypeAliasDataProvider
*
Something went wrong with that request. Please try again.