diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 6d497d7f4..8a8880606 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -766,7 +766,15 @@ public function __construct() ? new \ReflectionClass($metadata->name) : $metadata->reflClass; - return $reflClass->getTraits(); + $traits = array(); + + while ($reflClass !== false) { + $traits = array_merge($traits, $reflClass->getTraits()); + + $reflClass = $reflClass->getParentClass(); + } + + return $traits; } return array(); diff --git a/tests/Doctrine/Tests/Models/DDC2372/DDC2372Admin.php b/tests/Doctrine/Tests/Models/DDC2372/DDC2372Admin.php new file mode 100644 index 000000000..604e919f7 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC2372/DDC2372Admin.php @@ -0,0 +1,8 @@ +assertSame($reflClass->hasMethod('getAddress'), false); } + /** + * @group DDC-2372 + */ + public function testTraitPropertiesAndMethodsAreNotDuplicatedInChildClasses() + { + 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 DDC2372Admin(); + $metadata = $cmf->getMetadataFor(get_class($user)); + $metadata->name = $this->_namespace . "\DDC2372Admin"; + $metadata->namespace = $this->_namespace; + + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/DDC2372Admin.php"); + require $this->_tmpDir . "/" . $this->_namespace . "/DDC2372Admin.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 */