1
0
mirror of synced 2024-12-14 15:16:04 +03:00

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)

This commit is contained in:
beberlei 2010-08-28 16:29:08 +02:00
parent 2a2936fde5
commit c77a12ac83
2 changed files with 14 additions and 10 deletions

View File

@ -82,7 +82,7 @@ class EntityGenerator
private static $_classTemplate = private static $_classTemplate =
'<?php '<?php
<namespace><use> <namespace>
<entityAnnotation> <entityAnnotation>
<entityClassName> <entityClassName>
@ -189,7 +189,6 @@ public function <methodName>()
{ {
$placeHolders = array( $placeHolders = array(
'<namespace>', '<namespace>',
'<use>',
'<entityAnnotation>', '<entityAnnotation>',
'<entityClassName>', '<entityClassName>',
'<entityBody>' '<entityBody>'
@ -197,7 +196,6 @@ public function <methodName>()
$replacements = array( $replacements = array(
$this->_generateEntityNamespace($metadata), $this->_generateEntityNamespace($metadata),
$this->_generateEntityUse($metadata),
$this->_generateEntityDocBlock($metadata), $this->_generateEntityDocBlock($metadata),
$this->_generateEntityClassName($metadata), $this->_generateEntityClassName($metadata),
$this->_generateEntityBody($metadata) $this->_generateEntityBody($metadata)
@ -309,13 +307,6 @@ public function <methodName>()
} }
} }
private function _generateEntityUse(ClassMetadataInfo $metadata)
{
if ($this->_extendsClass()) {
return "\n\nuse " . $this->_getClassToExtendName() . ";\n";
}
}
private function _generateEntityClassName(ClassMetadataInfo $metadata) private function _generateEntityClassName(ClassMetadataInfo $metadata)
{ {
return 'class ' . $this->_getClassName($metadata) . return 'class ' . $this->_getClassName($metadata) .

View File

@ -20,6 +20,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$this->_generator->setGenerateStubMethods(true); $this->_generator->setGenerateStubMethods(true);
$this->_generator->setRegenerateEntityIfExists(false); $this->_generator->setRegenerateEntityIfExists(false);
$this->_generator->setUpdateEntityIfExists(true); $this->_generator->setUpdateEntityIfExists(true);
$this->_generator->setClassToExtend('stdClass');
} }
public function testWriteEntityClass() 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 getTest(') !== false);
$this->assertTrue(strstr($code, 'public function setTest(') !== 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'); unlink(__DIR__ . '/EntityGeneratorBook.php');
} }
} }