Skip to content

Commit

Permalink
Merge branch 'hotfix/#1352-entity-generator-new-class-metadata-hotfix…
Browse files Browse the repository at this point in the history
…-2.4' into 2.4

Close #1352
  • Loading branch information
Ocramius committed Mar 31, 2015
2 parents ecb1e10 + 2290d1f commit 0cf7e0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ protected function parseTokensInEntityFile($src)
*/
protected function hasProperty($property, ClassMetadataInfo $metadata)
{
if ($this->extendsClass() || class_exists($metadata->name)) {
if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) {
// don't generate property if its already on the base class.
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
if ($reflClass->hasProperty($property)) {
Expand All @@ -723,7 +723,7 @@ protected function hasProperty($property, ClassMetadataInfo $metadata)
*/
protected function hasMethod($method, ClassMetadataInfo $metadata)
{
if ($this->extendsClass() || class_exists($metadata->name)) {
if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) {
// don't generate method if its already on the base class.
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);

Expand Down
33 changes: 32 additions & 1 deletion tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,25 @@ public function testMethodsAndPropertiesAreNotDuplicatedInChildClasses()
$this->assertFalse($rc3->hasMethod('getCreatedAt'));
$this->assertFalse($rc3->hasMethod('setCreatedAt'));
}


public function testRegenerateEntityClass()
{
$metadata = $this->generateBookEntityFixture();
$this->loadEntityClass($metadata);

$className = basename(str_replace('\\', '/', $metadata->name));
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
$classTest = file_get_contents($path);

$this->_generator->setRegenerateEntityIfExists(true);
$this->_generator->setBackupExisting(false);

$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
$classNew = file_get_contents($path);

$this->assertSame($classTest,$classNew);
}

/**
* @return array
*/
Expand Down Expand Up @@ -639,6 +657,19 @@ public static function someMethod(){
);
}

/**
* @param ClassMetadataInfo $metadata
*/
private function loadEntityClass(ClassMetadataInfo $metadata)
{
$className = basename(str_replace('\\', '/', $metadata->name));
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';

$this->assertFileExists($path);

require_once $path;
}

/**
* @param string $type
* @param \ReflectionProperty $property
Expand Down

0 comments on commit 0cf7e0e

Please sign in to comment.