From d1dc72b65aff72e612904c82976bee461f39167e Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Tue, 27 Nov 2012 14:38:18 -0200 Subject: [PATCH] refactoring tests --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 4 +- .../Tests/ORM/Tools/EntityGeneratorTest.php | 48 ++++++++----------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 1838bf632..db2e834c4 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -139,7 +139,7 @@ class EntityGenerator /** * Hash-map for handle types - * + * * @var array */ protected $typeAlias = array( @@ -158,7 +158,7 @@ class EntityGenerator ); /** - * @var array Hash-map to handle generator types string + * @var array Hash-map to handle generator types string. */ protected static $generatorStrategyMap = array( ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO', diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index f0a7e37bd..a55b603d5 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -349,53 +349,49 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $method = new \ReflectionMethod($this->_generator, 'getInheritanceTypeString'); $constants = $reflection->getConstants(); $pattern = '/^INHERITANCE_TYPE_/'; - $map = array(); $method->setAccessible(true); foreach ($constants as $name => $value) { - if(preg_match($pattern, $name)) { - $map[preg_replace($pattern, '', $name)] = $value; + if( ! preg_match($pattern, $name)) { + continue; } - } - foreach ($map as $expected => $type) { - $actual = $method->invoke($this->_generator, $type); + $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'); + $this->setExpectedException('\InvalidArgumentException', 'Invalid provided InheritanceType: INVALID'); + $method->invoke($this->_generator, 'INVALID'); } - /** - * @group DDC-2172 - */ + /** + * @group DDC-2172 + */ public function testGetChangeTrackingPolicyString() { $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata'); $method = new \ReflectionMethod($this->_generator, 'getChangeTrackingPolicyString'); $constants = $reflection->getConstants(); $pattern = '/^CHANGETRACKING_/'; - $map = array(); $method->setAccessible(true); foreach ($constants as $name => $value) { - if(preg_match($pattern, $name)) { - $map[preg_replace($pattern, '', $name)] = $value; + if( ! preg_match($pattern, $name)) { + continue; } - } - foreach ($map as $expected => $type) { - $actual = $method->invoke($this->_generator, $type); + $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'); + $this->setExpectedException('\InvalidArgumentException', 'Invalid provided ChangeTrackingPolicy: INVALID'); + $method->invoke($this->_generator, 'INVALID'); } /** @@ -407,24 +403,22 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $method = new \ReflectionMethod($this->_generator, 'getIdGeneratorTypeString'); $constants = $reflection->getConstants(); $pattern = '/^GENERATOR_TYPE_/'; - $map = array(); $method->setAccessible(true); foreach ($constants as $name => $value) { - if(preg_match($pattern, $name)) { - $map[preg_replace($pattern, '', $name)] = $value; + if( ! preg_match($pattern, $name)) { + continue; } - } - foreach ($map as $expected => $type) { - $actual = $method->invoke($this->_generator, $type); + $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'); + $this->setExpectedException('\InvalidArgumentException', 'Invalid provided IdGeneratorType: INVALID'); + $method->invoke($this->_generator, 'INVALID'); } /**