From b9090ef73ee2d00b6d1c4dec61f9498cc46d2e2c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 10 Sep 2014 16:40:17 +0200 Subject: [PATCH 1/4] DDC-3272 - failing test (to be run in insulation because of autoloading) that verifies that a wrong annotation is generated for `@MappedSuperclass` --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 1a41dee83..07abaaaf6 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -284,6 +284,36 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals($cm->customRepositoryClassName, $metadata->customRepositoryClassName); } + /** + * @group DDC-3272 + */ + public function testMappedSuperclassAnnotationGeneration() + { + $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorBook'); + + $metadata->namespace = $this->_namespace; + $metadata->isMappedSuperclass = true; + + $this->_generator->setAnnotationPrefix('ORM\\'); + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + // force instantiation (causes autoloading to kick in) + $this->newInstance($metadata); + + $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver( + new \Doctrine\Common\Annotations\AnnotationReader(), + array() + ); + + $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); + + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + + $driver->loadMetadataForClass($cm->name, $cm); + + $this->assertTrue($cm->isMappedSuperclass); + } + /** * @dataProvider getParseTokensInEntityFileData */ From ffe38e5088a9149805b072f816b387725cd5e2e8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 10 Sep 2014 16:41:49 +0200 Subject: [PATCH 2/4] DDC-3272 - cleanups, importing classes, optimized imports --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 07abaaaf6..bb6eeab45 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -2,13 +2,15 @@ namespace Doctrine\Tests\ORM\Tools; -use Doctrine\ORM\Tools\SchemaTool; -use Doctrine\ORM\Tools\EntityGenerator; -use Doctrine\ORM\Tools\Export\ClassMetadataExporter; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; -use Doctrine\Tests\Models\DDC2372\DDC2372User; +use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\Tests\Models\DDC2372\DDC2372Admin; +use Doctrine\Tests\Models\DDC2372\DDC2372User; class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase { @@ -245,8 +247,8 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $book = $this->newInstance($metadata); - $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm = new ClassMetadata($metadata->name); + $cm->initializeReflection(new RuntimeReflectionService); $driver = $this->createAnnotationDriver(); $driver->loadMetadataForClass($cm->name, $cm); @@ -266,13 +268,13 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->_generator->setAnnotationPrefix('ORM\\'); $metadata = $this->generateBookEntityFixture(); - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); - $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array()); + $reader = new AnnotationReader(); + $driver = new AnnotationDriver($reader, array()); $book = $this->newInstance($metadata); - $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm = new ClassMetadata($metadata->name); + $cm->initializeReflection(new RuntimeReflectionService); $driver->loadMetadataForClass($cm->name, $cm); @@ -300,14 +302,11 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase // force instantiation (causes autoloading to kick in) $this->newInstance($metadata); - $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver( - new \Doctrine\Common\Annotations\AnnotationReader(), - array() - ); + $cm = new ClassMetadata($metadata->name); - $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); + $cm->initializeReflection(new RuntimeReflectionService); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $driver = new AnnotationDriver(new AnnotationReader(), array()); $driver->loadMetadataForClass($cm->name, $cm); From dd9a6bea0acfabb5e5a6cfda6846e2b8dd59d19b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 10 Sep 2014 16:57:35 +0200 Subject: [PATCH 3/4] DDC-3272 - minor cleanups - inspecting a test failure related with `@Doctrine\ORM\Mapping\Table` autoloading --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index bb6eeab45..172213dab 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -11,8 +11,9 @@ use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\Tests\Models\DDC2372\DDC2372Admin; use Doctrine\Tests\Models\DDC2372\DDC2372User; +use Doctrine\Tests\OrmTestCase; -class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase +class EntityGeneratorTest extends OrmTestCase { /** @@ -291,23 +292,18 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase */ public function testMappedSuperclassAnnotationGeneration() { - $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorBook'); - + $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorBook'); $metadata->namespace = $this->_namespace; $metadata->isMappedSuperclass = true; $this->_generator->setAnnotationPrefix('ORM\\'); $this->_generator->writeEntityClass($metadata, $this->_tmpDir); - - // force instantiation (causes autoloading to kick in) - $this->newInstance($metadata); - - $cm = new ClassMetadata($metadata->name); - - $cm->initializeReflection(new RuntimeReflectionService); + $this->newInstance($metadata); // force instantiation (causes autoloading to kick in) $driver = new AnnotationDriver(new AnnotationReader(), array()); + $cm = new ClassMetadata($metadata->name); + $cm->initializeReflection(new RuntimeReflectionService); $driver->loadMetadataForClass($cm->name, $cm); $this->assertTrue($cm->isMappedSuperclass); From 4974edc70ad2cd12768850b3bf3d335ee3e7a44e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 10 Sep 2014 17:00:06 +0200 Subject: [PATCH 4/4] DDC-3272 - fixing issue with mapped superclass name, minor refactoring --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 918e4162b..b4047da96 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -875,15 +875,13 @@ public function __construct() } } - if ($metadata->isMappedSuperclass) { - $lines[] = ' * @' . $this->annotationsPrefix . 'MappedSuperClass'; - } else { - $lines[] = ' * @' . $this->annotationsPrefix . 'Entity'; - } + $customRepository = $metadata->customRepositoryClassName + ? '(repositoryClass="' . $metadata->customRepositoryClassName . '")' + : ''; - if ($metadata->customRepositoryClassName) { - $lines[count($lines) - 1] .= '(repositoryClass="' . $metadata->customRepositoryClassName . '")'; - } + $lines[] = ' * @' . $this->annotationsPrefix + . ($metadata->isMappedSuperclass ? 'MappedSuperclass' : 'Entity') + . $customRepository; if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) { $lines[] = ' * @' . $this->annotationsPrefix . 'HasLifecycleCallbacks';