Skip to content

Commit

Permalink
Merge pull request doctrine#1132 from Ocramius/hotfix/DDC-3272-entity…
Browse files Browse the repository at this point in the history
…-generator-mapped-superclass-casing

DDC-3272 entity generator mapped superclass casing
  • Loading branch information
deeky666 committed Sep 10, 2014
2 parents e2fea42 + 4974edc commit b249aa9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
14 changes: 6 additions & 8 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,15 +875,13 @@ protected function generateEntityDocBlock(ClassMetadataInfo $metadata)
}
}

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';
Expand Down
49 changes: 37 additions & 12 deletions tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

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;
use Doctrine\Tests\OrmTestCase;

class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
class EntityGeneratorTest extends OrmTestCase
{

/**
Expand Down Expand Up @@ -245,8 +248,8 @@ public function testLoadMetadata()

$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);
Expand All @@ -266,13 +269,13 @@ public function testLoadPrefixedMetadata()
$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);

Expand All @@ -284,6 +287,28 @@ public function testLoadPrefixedMetadata()
$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);
$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);
}

/**
* @dataProvider getParseTokensInEntityFileData
*/
Expand Down

0 comments on commit b249aa9

Please sign in to comment.