Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #763 from Padam87/entgenparenttrait

Entity generator - trait in parent class
  • Loading branch information...
commit 44f9952063efd0da7295b0ac7ef802bbd3179958 2 parents cc83ac6 + b041c22
Guilherme Blanco guilhermeblanco authored
10 lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -766,7 +766,15 @@ protected function getTraits(ClassMetadataInfo $metadata)
766 766 ? new \ReflectionClass($metadata->name)
767 767 : $metadata->reflClass;
768 768
769   - return $reflClass->getTraits();
  769 + $traits = array();
  770 +
  771 + while ($reflClass !== false) {
  772 + $traits = array_merge($traits, $reflClass->getTraits());
  773 +
  774 + $reflClass = $reflClass->getParentClass();
  775 + }
  776 +
  777 + return $traits;
770 778 }
771 779
772 780 return array();
8 tests/Doctrine/Tests/Models/DDC2372/DDC2372Admin.php
... ... @@ -0,0 +1,8 @@
  1 +<?php
  2 +
  3 +namespace Doctrine\Tests\Models\DDC2372;
  4 +
  5 +/** @Entity @Table(name="admins") */
  6 +class DDC2372Admin extends DDC2372User
  7 +{
  8 +}
31 tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
@@ -8,6 +8,7 @@
8 8 use Doctrine\ORM\Mapping\ClassMetadataInfo;
9 9 use Doctrine\ORM\Mapping\ClassMetadataFactory;
10 10 use Doctrine\Tests\Models\DDC2372\DDC2372User;
  11 +use Doctrine\Tests\Models\DDC2372\DDC2372Admin;
11 12
12 13 require_once __DIR__ . '/../../TestInit.php';
13 14
@@ -487,6 +488,36 @@ public function testTraitPropertiesAndMethodsAreNotDuplicated()
487 488 }
488 489
489 490 /**
  491 + * @group DDC-2372
  492 + */
  493 + public function testTraitPropertiesAndMethodsAreNotDuplicatedInChildClasses()
  494 + {
  495 + if (PHP_VERSION_ID < 50400) {
  496 + $this->markTestSkipped('Traits are not available before php 5.4.');
  497 + }
  498 +
  499 + $cmf = new ClassMetadataFactory();
  500 + $em = $this->_getTestEntityManager();
  501 + $cmf->setEntityManager($em);
  502 +
  503 + $user = new DDC2372Admin();
  504 + $metadata = $cmf->getMetadataFor(get_class($user));
  505 + $metadata->name = $this->_namespace . "\DDC2372Admin";
  506 + $metadata->namespace = $this->_namespace;
  507 +
  508 + $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
  509 +
  510 + $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/DDC2372Admin.php");
  511 + require $this->_tmpDir . "/" . $this->_namespace . "/DDC2372Admin.php";
  512 +
  513 + $reflClass = new \ReflectionClass($metadata->name);
  514 +
  515 + $this->assertSame($reflClass->hasProperty('address'), false);
  516 + $this->assertSame($reflClass->hasMethod('setAddress'), false);
  517 + $this->assertSame($reflClass->hasMethod('getAddress'), false);
  518 + }
  519 +
  520 + /**
490 521 * @return array
491 522 */
492 523 public function getEntityTypeAliasDataProvider()

0 comments on commit 44f9952

Please sign in to comment.
Something went wrong with that request. Please try again.