From c77a12ac83c82c00376593feadeb50b041aa8f29 Mon Sep 17 00:00:00 2001 From: beberlei Date: Sat, 28 Aug 2010 16:29:08 +0200 Subject: [PATCH] DDC-770 - Refactored EntityGenerator Bugfix NOT to generate a use statement. Simplifies code and circumvents further problems (like importing a class from the namespace we are in) --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 11 +---------- .../Tests/ORM/Tools/EntityGeneratorTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 616c60a9d..230ab98b9 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -82,7 +82,7 @@ class EntityGenerator private static $_classTemplate = ' + @@ -189,7 +189,6 @@ public function () { $placeHolders = array( '', - '', '', '', '' @@ -197,7 +196,6 @@ public function () $replacements = array( $this->_generateEntityNamespace($metadata), - $this->_generateEntityUse($metadata), $this->_generateEntityDocBlock($metadata), $this->_generateEntityClassName($metadata), $this->_generateEntityBody($metadata) @@ -309,13 +307,6 @@ public function () } } - private function _generateEntityUse(ClassMetadataInfo $metadata) - { - if ($this->_extendsClass()) { - return "\n\nuse " . $this->_getClassToExtendName() . ";\n"; - } - } - private function _generateEntityClassName(ClassMetadataInfo $metadata) { return 'class ' . $this->_getClassName($metadata) . diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index ef4f51353..8a5431094 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -20,6 +20,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->_generator->setGenerateStubMethods(true); $this->_generator->setRegenerateEntityIfExists(false); $this->_generator->setUpdateEntityIfExists(true); + $this->_generator->setClassToExtend('stdClass'); } public function testWriteEntityClass() @@ -100,6 +101,18 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(strstr($code, 'public function getTest(') !== false); $this->assertTrue(strstr($code, 'public function setTest(') !== false); + return $metadata; + } + + /** + * @depends testEntityUpdatingWorks + * @param ClassMetadata $metadata + */ + public function testEntityExtendsStdClass($metadata) + { + $book = new \EntityGeneratorBook(); + $this->assertType('stdClass', $book); + unlink(__DIR__ . '/EntityGeneratorBook.php'); } }