Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity generator - trait in parent class #763

Merged
merged 1 commit into from
Aug 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,15 @@ protected function getTraits(ClassMetadataInfo $metadata)
? 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();
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/Models/DDC2372/DDC2372Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Doctrine\Tests\Models\DDC2372;

/** @Entity @Table(name="admins") */
class DDC2372Admin extends DDC2372User
{
}
31 changes: 31 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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';

Expand Down Expand Up @@ -486,6 +487,36 @@ public function testTraitPropertiesAndMethodsAreNotDuplicated()
$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
*/
Expand Down