From 0a90ca388197c768c4b026b2f11e392c9383f2c2 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Thu, 21 Jun 2012 23:00:13 +0200 Subject: [PATCH] Changed return tag to properly support expanding types --- .../Reflection/DocBlock/Tag/ReturnTag.php | 21 ----- .../Reflection/DocBlock/Tag/ReturnTagTest.php | 81 +++++++++++++++++++ 2 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php index 95a0c2d..88c631b 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -42,25 +42,4 @@ class ReturnTag extends ParamTag $this->description = implode(' ', $content); } - /** - * Returns the type of the variable. - * - * @return string - */ - public function getTypes() - { - $types = explode('|', $this->type); - array_walk($types, 'trim'); - return $types; - } - - /** - * Returns the type of the variable. - * - * @return string - */ - public function getType() - { - return $this->type; - } } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php new file mode 100644 index 0000000..1cc95be --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -0,0 +1,81 @@ + + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +require_once __DIR__ + . '/../../../../../src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php'; + +/** + * Test class for phpDocumentor_Reflection_DocBlock_ReturnTag. + * + * @author Mike van Riel + * @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + */ +class ReturnTagTest extends ParamTagTest +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can + * understand the Return DocBlock. + * + * @param string $content + * @param string $extracted_type + * @param string $extracted_description + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct + * + * @dataProvider provideDataForConstructor + * + * @return void + */ + public function testConstructorParsesInputsIntoCorrectFields( + $content, $extracted_type, $extracted_description + ) { + $tag = new ReturnTag('return', $content); + + $this->assertEquals($extracted_type, $tag->getTypes()); + $this->assertEquals($extracted_description, $tag->getDescription()); + } + + /** + * Tests whether the getTypes method correctly converts the given tags. + * + * @param string $type Type string to test + * @param string[] $expected Array of expected types + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes() + * + * @dataProvider provideTypesToExpand + * + * @return void + */ + public function testExpandTypeIntoCorrectFcqn($type, $expected) + { + $docblock = new \phpDocumentor\Reflection\DocBlock( + '', '\My\Namespace', array('Alias' => '\My\Namespace\Aliasing') + ); + + $tag = new ReturnTag('return', $type); + $tag->setDocBlock($docblock); + $this->assertEquals($expected, $tag->getTypes()); + } + + /** + * Data provider for testConstructorParsesInputsIntoCorrectFields() + * + * @return array + */ + public function provideDataForConstructor() + { + return array( + array('', array(''), ''), + array('int', array('int'), ''), + array('int Number of Bobs', array('int'), 'Number of Bobs'), + ); + } +}