From 521276f1ede77794f71b3e4cd3c315ac668ca412 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Tue, 26 Mar 2013 20:52:57 +0100 Subject: [PATCH 01/11] entity generator - ignore trait properties and methods --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 082720bf7..945bbd935 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -709,6 +709,15 @@ public function __construct() } } + // check traits for existing property + $reflClass = new \ReflectionClass($metadata->name); + + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasProperty($property)) { + return true; + } + } + return ( isset($this->staticReflection[$metadata->name]) && in_array($property, $this->staticReflection[$metadata->name]['properties']) @@ -732,6 +741,15 @@ public function __construct() } } + // check traits for existing method + $reflClass = new \ReflectionClass($metadata->name); + + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasMethod($method)) { + return true; + } + } + return ( isset($this->staticReflection[$metadata->name]) && in_array($method, $this->staticReflection[$metadata->name]['methods']) From bb5bdcf0f4ccd6fc83692490ec70a697c90573fb Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Tue, 26 Mar 2013 21:14:52 +0100 Subject: [PATCH 02/11] only use already existing reflections --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 945bbd935..97a40e8ad 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -710,11 +710,13 @@ public function __construct() } // check traits for existing property - $reflClass = new \ReflectionClass($metadata->name); + if (isset($this->staticReflection[$metadata->name])) { + $reflClass = $this->staticReflection[$metadata->name]; - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasProperty($property)) { - return true; + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasProperty($property)) { + return true; + } } } @@ -742,11 +744,13 @@ public function __construct() } // check traits for existing method - $reflClass = new \ReflectionClass($metadata->name); + if (isset($this->staticReflection[$metadata->name])) { + $reflClass = $this->staticReflection[$metadata->name]; - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasMethod($method)) { - return true; + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasMethod($method)) { + return true; + } } } From 8e3e2e770a2271caf15899cb3f9a840d94443fa7 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Tue, 26 Mar 2013 21:17:59 +0100 Subject: [PATCH 03/11] Revert "only use already existing reflections" This reverts commit bb5bdcf0f4ccd6fc83692490ec70a697c90573fb. --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 97a40e8ad..945bbd935 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -710,13 +710,11 @@ public function __construct() } // check traits for existing property - if (isset($this->staticReflection[$metadata->name])) { - $reflClass = $this->staticReflection[$metadata->name]; + $reflClass = new \ReflectionClass($metadata->name); - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasProperty($property)) { - return true; - } + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasProperty($property)) { + return true; } } @@ -744,13 +742,11 @@ public function __construct() } // check traits for existing method - if (isset($this->staticReflection[$metadata->name])) { - $reflClass = $this->staticReflection[$metadata->name]; + $reflClass = new \ReflectionClass($metadata->name); - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasMethod($method)) { - return true; - } + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasMethod($method)) { + return true; } } From 8898c91dfc1c6a433fc6cb1de5235c35a46f25b7 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Tue, 26 Mar 2013 21:28:09 +0100 Subject: [PATCH 04/11] only check for traits when class exists --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 945bbd935..2946935b3 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -710,11 +710,13 @@ public function __construct() } // check traits for existing property - $reflClass = new \ReflectionClass($metadata->name); + if (class_exists($metadata->name)) { + $reflClass = new \ReflectionClass($metadata->name); - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasProperty($property)) { - return true; + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasProperty($property)) { + return true; + } } } @@ -742,11 +744,13 @@ public function __construct() } // check traits for existing method - $reflClass = new \ReflectionClass($metadata->name); + if (class_exists($metadata->name)) { + $reflClass = new \ReflectionClass($metadata->name); - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasMethod($method)) { - return true; + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasMethod($method)) { + return true; + } } } From 9797177193b4757df7d3f06cd60c7e06e559aa74 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Wed, 27 Mar 2013 02:48:35 +0100 Subject: [PATCH 05/11] check if ReflectionClass::getTraits() method exists --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 2946935b3..6aad04fb6 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -713,9 +713,11 @@ public function __construct() if (class_exists($metadata->name)) { $reflClass = new \ReflectionClass($metadata->name); - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasProperty($property)) { - return true; + if (method_exists($reflClass, 'getTraits')) { + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasProperty($property)) { + return true; + } } } } @@ -747,9 +749,11 @@ public function __construct() if (class_exists($metadata->name)) { $reflClass = new \ReflectionClass($metadata->name); - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasMethod($method)) { - return true; + if (method_exists($reflClass, 'getTraits')) { + foreach ($reflClass->getTraits() as $trait) { + if ($trait->hasMethod($method)) { + return true; + } } } } From 937ba6385e6823c183daf2230b1447dbbbedfcec Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Sun, 31 Mar 2013 00:47:24 +0100 Subject: [PATCH 06/11] fixed code duplication issue --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 44 +++++++++++++--------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 6aad04fb6..948a4e689 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -710,15 +710,9 @@ public function __construct() } // check traits for existing property - if (class_exists($metadata->name)) { - $reflClass = new \ReflectionClass($metadata->name); - - if (method_exists($reflClass, 'getTraits')) { - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasProperty($property)) { - return true; - } - } + foreach ($this->getTraits($metadata) as $trait) { + if ($trait->hasProperty($property)) { + return true; } } @@ -746,15 +740,9 @@ public function __construct() } // check traits for existing method - if (class_exists($metadata->name)) { - $reflClass = new \ReflectionClass($metadata->name); - - if (method_exists($reflClass, 'getTraits')) { - foreach ($reflClass->getTraits() as $trait) { - if ($trait->hasMethod($method)) { - return true; - } - } + foreach ($this->getTraits($metadata) as $trait) { + if ($trait->hasMethod($method)) { + return true; } } @@ -764,6 +752,26 @@ public function __construct() ); } + /** + * @param ClassMetadataInfo $metadata + * + * @return array + */ + protected function getTraits(ClassMetadataInfo $metadata) + { + if ($metadata->reflClass != null || class_exists($metadata->name)) { + $reflClass = $metadata->reflClass == null + ? new \ReflectionClass($metadata->name) + : $metadata->reflClass; + + if (method_exists($reflClass, 'getTraits')) { + return $reflClass->getTraits(); + } + } + + return array(); + } + /** * @param ClassMetadataInfo $metadata * From b3414e3c1ab70050d2b0a206e74bf827cb39f8f4 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Sun, 31 Mar 2013 00:47:45 +0100 Subject: [PATCH 07/11] added unit test --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 58 ++++++++++++++----- tests/Doctrine/Tests/TestInit.php | 1 + tools/sandbox/Entities/TraitedUser.php | 34 +++++++++++ .../sandbox/Entities/Traits/AddressTrait.php | 25 ++++++++ 4 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 tools/sandbox/Entities/TraitedUser.php create mode 100644 tools/sandbox/Entities/Traits/AddressTrait.php diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index a55b603d5..694918d13 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -2,10 +2,12 @@ namespace Doctrine\Tests\ORM\Tools; -use Doctrine\ORM\Tools\SchemaTool, - Doctrine\ORM\Tools\EntityGenerator, - Doctrine\ORM\Tools\Export\ClassMetadataExporter, - Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\ORM\Tools\EntityGenerator; +use Doctrine\ORM\Tools\Export\ClassMetadataExporter; +use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Entities\TraitedUser; require_once __DIR__ . '/../../TestInit.php'; @@ -282,7 +284,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $filename = $this->_tmpDir . DIRECTORY_SEPARATOR . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC1784Entity.php'; - + $this->assertFileExists($filename); require_once $filename; @@ -330,7 +332,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $property = new \ReflectionProperty($metadata->name, 'centroCustos'); $docComment = $property->getDocComment(); - + //joinColumns $this->assertContains('@JoinColumn(name="idorcamento", referencedColumnName="idorcamento"),', $docComment); $this->assertContains('@JoinColumn(name="idunidade", referencedColumnName="idunidade")', $docComment); @@ -436,7 +438,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $entity = new $metadata->name; $reflClass = new \ReflectionClass($metadata->name); - + $type = $field['phpType']; $name = $field['fieldName']; $value = $field['value']; @@ -451,6 +453,34 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals($value, $entity->{$getter}()); } + /** + * @group DDC-2372 + */ + public function testTraitPropertiesAndMethodsAreNotDuplicated() + { + if (function_exists('trait_exists')) { + $cmf = new ClassMetadataFactory(); + $em = $this->_getTestEntityManager(); + $cmf->setEntityManager($em); + + $user = new TraitedUser(); + $metadata = $cmf->getMetadataFor(get_class($user)); + $metadata->name = $this->_namespace . "\TraitedUser"; + $metadata->namespace = $this->_namespace; + + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/TraitedUser.php"); + require $this->_tmpDir . "/" . $this->_namespace . "/TraitedUser.php"; + + $reflClass = new \ReflectionClass($metadata->name); + + $this->assertSame($reflClass->hasProperty('address'), false); + $this->assertSame($reflClass->hasMethod('setAddress'), false); + $this->assertSame($reflClass->hasMethod('getAddress'), false); + } + } + /** * @return array */ @@ -470,43 +500,43 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase 'value' => new \DateTime )), array(array( - 'fieldName' => 'date', + 'fieldName' => 'date', 'phpType' => '\\DateTime', 'dbType' => 'date', 'value' => new \DateTime )), array(array( - 'fieldName' => 'time', + 'fieldName' => 'time', 'phpType' => '\DateTime', 'dbType' => 'time', 'value' => new \DateTime )), array(array( - 'fieldName' => 'object', + 'fieldName' => 'object', 'phpType' => '\stdClass', 'dbType' => 'object', 'value' => new \stdClass() )), array(array( - 'fieldName' => 'bigint', + 'fieldName' => 'bigint', 'phpType' => 'integer', 'dbType' => 'bigint', 'value' => 11 )), array(array( - 'fieldName' => 'smallint', + 'fieldName' => 'smallint', 'phpType' => 'integer', 'dbType' => 'smallint', 'value' => 22 )), array(array( - 'fieldName' => 'text', + 'fieldName' => 'text', 'phpType' => 'string', 'dbType' => 'text', 'value' => 'text' )), array(array( - 'fieldName' => 'blob', + 'fieldName' => 'blob', 'phpType' => 'string', 'dbType' => 'blob', 'value' => 'blob' diff --git a/tests/Doctrine/Tests/TestInit.php b/tests/Doctrine/Tests/TestInit.php index c257a75b6..ac7f7354b 100644 --- a/tests/Doctrine/Tests/TestInit.php +++ b/tests/Doctrine/Tests/TestInit.php @@ -17,6 +17,7 @@ if (file_exists(__DIR__ . '/../../../vendor/autoload.php')) { } /* @var $classLoader \Composer\Autoload\ClassLoader */ +$classLoader->add('Entities', __DIR__ . '/../../../tools/sandbox'); $classLoader->add('Doctrine\\Tests\\', __DIR__ . '/../../'); unset($classLoader); diff --git a/tools/sandbox/Entities/TraitedUser.php b/tools/sandbox/Entities/TraitedUser.php new file mode 100644 index 000000000..fe0b68754 --- /dev/null +++ b/tools/sandbox/Entities/TraitedUser.php @@ -0,0 +1,34 @@ +id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } +} \ No newline at end of file diff --git a/tools/sandbox/Entities/Traits/AddressTrait.php b/tools/sandbox/Entities/Traits/AddressTrait.php new file mode 100644 index 000000000..9fb3e23a5 --- /dev/null +++ b/tools/sandbox/Entities/Traits/AddressTrait.php @@ -0,0 +1,25 @@ +address; + } + + public function setAddress(Address $address) + { + if ($this->address !== $address) { + $this->address = $address; + $address->setUser($this); + } + } +} \ No newline at end of file From 3b7b457d35657911d551ef69639e4a9db111501c Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Thu, 4 Apr 2013 20:07:21 +0200 Subject: [PATCH 08/11] minor fixes --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 6 +++--- tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 948a4e689..1c55eb1bc 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -759,12 +759,12 @@ public function __construct() */ protected function getTraits(ClassMetadataInfo $metadata) { - if ($metadata->reflClass != null || class_exists($metadata->name)) { - $reflClass = $metadata->reflClass == null + if ($metadata->reflClass !== null || class_exists($metadata->name)) { + $reflClass = $metadata->reflClass === null ? new \ReflectionClass($metadata->name) : $metadata->reflClass; - if (method_exists($reflClass, 'getTraits')) { + if (PHP_VERSION_ID >= 50400) { return $reflClass->getTraits(); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 694918d13..cd6430a2a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -458,7 +458,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase */ public function testTraitPropertiesAndMethodsAreNotDuplicated() { - if (function_exists('trait_exists')) { + if (PHP_VERSION_ID >= 50400) { $cmf = new ClassMetadataFactory(); $em = $this->_getTestEntityManager(); $cmf->setEntityManager($em); From b7b107b08ac22ec385b6461538832bd25e6f6547 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Sun, 7 Apr 2013 16:26:05 +0200 Subject: [PATCH 09/11] moved test entities from sandbox --- .../Tests/Models/DDC2372/DDC2372Address.php | 45 +++++++++++++++++++ .../Tests/Models/DDC2372/DDC2372User.php | 10 ++--- .../DDC2372/Traits/DDC2372AddressTrait.php | 6 +-- .../Tests/ORM/Tools/EntityGeneratorTest.php | 10 ++--- tests/Doctrine/Tests/TestInit.php | 1 - 5 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/DDC2372/DDC2372Address.php rename tools/sandbox/Entities/TraitedUser.php => tests/Doctrine/Tests/Models/DDC2372/DDC2372User.php (68%) rename tools/sandbox/Entities/Traits/AddressTrait.php => tests/Doctrine/Tests/Models/DDC2372/Traits/DDC2372AddressTrait.php (69%) diff --git a/tests/Doctrine/Tests/Models/DDC2372/DDC2372Address.php b/tests/Doctrine/Tests/Models/DDC2372/DDC2372Address.php new file mode 100644 index 000000000..26144c61d --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC2372/DDC2372Address.php @@ -0,0 +1,45 @@ +id; + } + + public function getStreet() + { + return $this->street; + } + + public function setStreet($street) + { + $this->street = $street; + } + + public function getUser() + { + return $this->user; + } + + public function setUser(User $user) + { + if ($this->user !== $user) { + $this->user = $user; + $user->setAddress($this); + } + } +} \ No newline at end of file diff --git a/tools/sandbox/Entities/TraitedUser.php b/tests/Doctrine/Tests/Models/DDC2372/DDC2372User.php similarity index 68% rename from tools/sandbox/Entities/TraitedUser.php rename to tests/Doctrine/Tests/Models/DDC2372/DDC2372User.php index fe0b68754..4df0df6a5 100644 --- a/tools/sandbox/Entities/TraitedUser.php +++ b/tests/Doctrine/Tests/Models/DDC2372/DDC2372User.php @@ -1,13 +1,13 @@ _getTestEntityManager(); $cmf->setEntityManager($em); - $user = new TraitedUser(); + $user = new DDC2372User(); $metadata = $cmf->getMetadataFor(get_class($user)); - $metadata->name = $this->_namespace . "\TraitedUser"; + $metadata->name = $this->_namespace . "\DDC2372User"; $metadata->namespace = $this->_namespace; $this->_generator->writeEntityClass($metadata, $this->_tmpDir); - $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/TraitedUser.php"); - require $this->_tmpDir . "/" . $this->_namespace . "/TraitedUser.php"; + $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"); + require $this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"; $reflClass = new \ReflectionClass($metadata->name); diff --git a/tests/Doctrine/Tests/TestInit.php b/tests/Doctrine/Tests/TestInit.php index ac7f7354b..c257a75b6 100644 --- a/tests/Doctrine/Tests/TestInit.php +++ b/tests/Doctrine/Tests/TestInit.php @@ -17,7 +17,6 @@ if (file_exists(__DIR__ . '/../../../vendor/autoload.php')) { } /* @var $classLoader \Composer\Autoload\ClassLoader */ -$classLoader->add('Entities', __DIR__ . '/../../../tools/sandbox'); $classLoader->add('Doctrine\\Tests\\', __DIR__ . '/../../'); unset($classLoader); From bf92a40171e98c47a9c607bcded37daa0cb89a93 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Fri, 19 Apr 2013 14:49:32 +0200 Subject: [PATCH 10/11] skip test if php 5.3 --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index bdf2090ef..f687d06ed 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -458,27 +458,29 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase */ public function testTraitPropertiesAndMethodsAreNotDuplicated() { - if (PHP_VERSION_ID >= 50400) { - $cmf = new ClassMetadataFactory(); - $em = $this->_getTestEntityManager(); - $cmf->setEntityManager($em); - - $user = new DDC2372User(); - $metadata = $cmf->getMetadataFor(get_class($user)); - $metadata->name = $this->_namespace . "\DDC2372User"; - $metadata->namespace = $this->_namespace; - - $this->_generator->writeEntityClass($metadata, $this->_tmpDir); - - $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"); - require $this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"; - - $reflClass = new \ReflectionClass($metadata->name); - - $this->assertSame($reflClass->hasProperty('address'), false); - $this->assertSame($reflClass->hasMethod('setAddress'), false); - $this->assertSame($reflClass->hasMethod('getAddress'), false); + if (PHP_VERSION_ID < 50400) { + $this->markTestSkipped('Traits are not available before php 5.4.'); } + + $cmf = new ClassMetadataFactory(); + $em = $this->_getTestEntityManager(); + $cmf->setEntityManager($em); + + $user = new DDC2372User(); + $metadata = $cmf->getMetadataFor(get_class($user)); + $metadata->name = $this->_namespace . "\DDC2372User"; + $metadata->namespace = $this->_namespace; + + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"); + require $this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"; + + $reflClass = new \ReflectionClass($metadata->name); + + $this->assertSame($reflClass->hasProperty('address'), false); + $this->assertSame($reflClass->hasMethod('setAddress'), false); + $this->assertSame($reflClass->hasMethod('getAddress'), false); } /** From 73e2aa54ef72d8278e3a9f0a968b18b39d685a46 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Fri, 14 Jun 2013 10:07:05 +0200 Subject: [PATCH 11/11] moved php version check --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 1c55eb1bc..42a6e85c9 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -759,14 +759,12 @@ public function __construct() */ protected function getTraits(ClassMetadataInfo $metadata) { - if ($metadata->reflClass !== null || class_exists($metadata->name)) { + if (PHP_VERSION_ID >= 50400 && ($metadata->reflClass !== null || class_exists($metadata->name))) { $reflClass = $metadata->reflClass === null ? new \ReflectionClass($metadata->name) : $metadata->reflClass; - if (PHP_VERSION_ID >= 50400) { - return $reflClass->getTraits(); - } + return $reflClass->getTraits(); } return array();