1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Merge pull request #763 from Padam87/entgenparenttrait

Entity generator - trait in parent class
This commit is contained in:
Guilherme Blanco 2013-08-20 05:38:02 -07:00
commit 44f9952063
3 changed files with 48 additions and 1 deletions

View File

@ -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();

View File

@ -0,0 +1,8 @@
<?php
namespace Doctrine\Tests\Models\DDC2372;
/** @Entity @Table(name="admins") */
class DDC2372Admin extends DDC2372User
{
}

View File

@ -8,6 +8,7 @@ use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\Tests\Models\DDC2372\DDC2372User;
use Doctrine\Tests\Models\DDC2372\DDC2372Admin;
require_once __DIR__ . '/../../TestInit.php';
@ -486,6 +487,36 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$this->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
*/