From 2f7e970c5f7bb47e0b7a3a3c96430af262ebcbe4 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 5 Nov 2012 21:53:07 -0200 Subject: [PATCH] Fix DDC-2121 --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 11 ++++++++--- .../Tests/ORM/Tools/EntityGeneratorTest.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index e4ddb80fd..cda778a44 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -915,9 +915,14 @@ public function __construct() $var = sprintf('%sMethodTemplate', $type); $template = self::$$var; + $methodTypeHint = null; $types = Type::getTypesMap(); $variableType = $typeHint ? $this->getType($typeHint) . ' ' : null; - $methodTypeHint = $typeHint && ! isset($types[$typeHint]) ? '\\' . $typeHint . ' ' : null; + + if ($typeHint && ! isset($types[$typeHint])) { + $variableType = '\\' . ltrim($variableType, '\\'); + $methodTypeHint = '\\' . $typeHint . ' '; + } $replacements = array( '' => ucfirst($type) . ' ' . $fieldName, @@ -997,9 +1002,9 @@ public function __construct() $lines[] = $this->spaces . '/**'; if ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) { - $lines[] = $this->spaces . ' * @var \Doctrine\Common\Collections\ArrayCollection'; + $lines[] = $this->spaces . ' * @var \Doctrine\Common\Collections\Collection'; } else { - $lines[] = $this->spaces . ' * @var ' . $associationMapping['targetEntity']; + $lines[] = $this->spaces . ' * @var \\' . ltrim($associationMapping['targetEntity'], '\\'); } if ($this->generateAnnotations) { diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index da7173165..142b68a48 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -167,6 +167,24 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue($reflClass->getMethod('getTest')->isPublic(), "Check for public visibility of method 'getTest' failed."); } + /** + * @group DDC-2121 + */ + public function testMethodDocBlockShouldStartWithBackSlash() + { + $metadata = $this->generateBookEntityFixture(); + $book = $this->newInstance($metadata); + + $this->assertPhpDocVarType('\Doctrine\Common\Collections\Collection', new \ReflectionProperty($book, 'comments')); + $this->assertPhpDocReturnType('\Doctrine\Common\Collections\Collection', new \ReflectionMethod($book, 'getComments')); + $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorComment', new \ReflectionMethod($book, 'addComment')); + $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorComment', new \ReflectionMethod($book, 'removeComment')); + + $this->assertPhpDocVarType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionProperty($book, 'author')); + $this->assertPhpDocReturnType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionMethod($book, 'getAuthor')); + $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionMethod($book, 'setAuthor')); + } + public function testEntityExtendsStdClass() { $this->_generator->setClassToExtend('stdClass');