8000 Merge branch 'hotfix/#1352-entity-generator-new-class-metadata-hotfix… · symfonyaml/orm@0cf7e0e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cf7e0e

Browse files
committed
Merge branch 'hotfix/doctrine#1352-entity-generator-new-class-metadata-hotfix-2.4' into 2.4
Close doctrine#1352
2 parents ecb1e10 + 2290d1f commit 0cf7e0e

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/Doctrine/ORM/Tools/EntityGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ protected function parseTokensInEntityFile($src)
701701
*/
702702
protected function hasProperty($property, ClassMetadataInfo $metadata)
703703
{
704-
if ($this->extendsClass() || class_exists($metadata->name)) {
704+
if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) {
705705
// don't generate property if its already on the base class.
706706
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
707707
if ($reflClass->hasProperty($property)) {
@@ -723,7 +723,7 @@ protected function hasProperty($property, ClassMetadataInfo $metadata)
723723
*/
724724
protected function hasMethod($method, ClassMetadataInfo $metadata)
725725
{
726-
if ($this->extendsClass() || class_exists($metadata->name)) {
726+
if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) {
727727
// don't generate method if its already on the base class.
728728
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
729729

tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,25 @@ public function testMethodsAndPropertiesAreNotDuplicatedInChildClasses()
527527
$this->assertFalse($rc3->hasMethod('getCreatedAt'));
528528
$this->assertFalse($rc3->hasMethod('setCreatedAt'));
529529
}
530-
530+
531+
public function testRegenerateEntityClass()
532+
{
533+
$metadata = $this->generateBookEntityFixture();
534+
$this->loadEntityClass($metadata);
535+
536+
$className = basename(str_replace('\\', '/', $metadata->name));
537+
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
538+
$classTest = file_get_contents($path);
539+
540+
$this->_generator->setRegenerateEntityIfExists(true);
541+
$this->_generator->setBackupExisting(false);
542+
543+
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
544+
$classNew = file_get_contents($path);
545+
546+
$this->assertSame($classTest,$classNew);
547+
}
548+
531549
/**
532550
* @return array
533551
*/
@@ -639,6 +657,19 @@ public static function someMethod(){
639657
);
640658
}
641659

660+
/**
661+
* @param ClassMetadataInfo $metadata
662+
*/
663+
private function loadEntityClass(ClassMetadataInfo $metadata)
664+
{
665+
$className = basename(str_replace('\\', '/', $metadata->name));
666+
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
667+
668+
$this->assertFileExists($path);
669+
670+
require_once $path;
671+
}
672+
642673
/**
643674
* @param string $type
644675
* @param \ReflectionProperty $property

0 commit comments

Comments
 (0)
0