From 6602ce0375474a22d090a00fcf3294904f7d708e Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sun, 11 Nov 2012 19:51:04 +0200 Subject: [PATCH] @return now trims the content before splitting it; Removed ThrowTag.php (unnecessary, given the map, which aliases "throw" to ThrowsTag.php); Added tests for ThrowsTag, along with a few other minor test additions and fixes; --- .../Reflection/DocBlock/Tag/ReturnTag.php | 2 +- .../Reflection/DocBlock/Tag/ThrowTag.php | 43 --------- .../Reflection/DocBlock/Tag/ParamTagTest.php | 48 ++++++++-- .../Reflection/DocBlock/Tag/ReturnTagTest.php | 26 ++++- .../Reflection/DocBlock/Tag/ThrowsTagTest.php | 96 +++++++++++++++++++ .../Reflection/DocBlock/Tag/UsesTagTest.php | 2 +- .../phpDocumentor/Reflection/DocBlockTest.php | 26 +++++ 7 files changed, 187 insertions(+), 56 deletions(-) delete mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php index 2d83b63..da22677 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -37,7 +37,7 @@ class ReturnTag extends Tag $this->tag = $type; $this->content = $content; - $content = preg_split('/[\ \t]+/u', $content, 2); + $content = preg_split('/[\ \t]+/u', trim($content), 2); // any output is considered a type $this->type = array_shift($content); diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php deleted file mode 100644 index 63e7a9a..0000000 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ - -namespace phpDocumentor\Reflection\DocBlock\Tag; - -/** - * Reflection class for a mistyped @throws tag called @throw in a Docblock. - * - * This is a very common error, so @throw is aliased to be @throws - * - * @author Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ -class ThrowTag extends ThrowsTag -{ - /** - * Sets the type to @throws and lets parent parse the tag and populates the - * member variables. - * - * @param string $type Tag identifier for this tag (should be 'throw'). - * @param string $content Contents for this tag. - */ - public function __construct($type, $content) - { - if ('throw' !== $type) { - throw new \InvalidArgumentException( - 'Internal error, ' . __CLASS__ . ' was called with ' . $type - ); - } - - parent::__construct('throws', $content); - } -} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php index 5f1051d..c0a370c 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php @@ -68,22 +68,52 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase array('param', 'int', 'int', array('int'), '', ''), array('param', '$bob', '', array(), '$bob', ''), array( - 'param', 'int Number of bobs', 'int', array('int'), '', + 'param', + 'int Number of bobs', + 'int', + array('int'), + '', 'Number of bobs' ), - array('param', 'int $bob', 'int', array('int'), '$bob', ''), array( - 'param', 'int $bob Number of bobs', 'int', array('int'), '$bob', + 'param', + 'int $bob', + 'int', + array('int'), + '$bob', + '' + ), + array( + 'param', + 'int $bob Number of bobs', + 'int', + array('int'), + '$bob', 'Number of bobs' ), - array('param', "int Description \n on multiple lines", 'int', - array('int'), '', "Description \n on multiple lines" + array( + 'param', + "int Description \n on multiple lines", + 'int', + array('int'), + '', + "Description \n on multiple lines" ), - array('param', "int \n\$bob Variable name on a new line", 'int', - array('int'), '$bob', "Variable name on a new line" + array( + 'param', + "int \n\$bob Variable name on a new line", + 'int', + array('int'), + '$bob', + "Variable name on a new line" ), - array('param', "\nint \$bob Type on a new line", 'int', - array('int'), '$bob', "Type on a new line" + array( + 'param', + "\nint \$bob Type on a new line", + 'int', + array('int'), + '$bob', + "Type on a new line" ) ); } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php index a84e333..5eef162 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -26,14 +26,15 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase * Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can * understand the @return DocBlock. * + * @param string $type * @param string $content * @param string $extractedType * @param string $extractedTypes * @param string $extractedDescription * * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getType - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getTypes + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getType + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes * * @dataProvider provideDataForConstructor * @@ -71,6 +72,27 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase array('int'), 'Number of Bobs' ), + array( + 'return', + 'int|double Number of Bobs', + 'int|double', + array('int', 'double'), + 'Number of Bobs' + ), + array( + 'return', + "int Number of \n Bobs", + 'int', + array('int'), + "Number of \n Bobs" + ), + array( + 'return', + " int Number of Bobs", + 'int', + array('int'), + "Number of Bobs" + ) ); } } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php new file mode 100644 index 0000000..124c469 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php @@ -0,0 +1,96 @@ + + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +/** + * Test class for \phpDocumentor\Reflection\DocBlock\ReturnTag. + * + * @author Mike van Riel + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class ThrowsTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can + * understand the @return DocBlock. + * + * @param string $type + * @param string $content + * @param string $extractedType + * @param string $extractedTypes + * @param string $extractedDescription + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag + * + * @dataProvider provideDataForConstructor + * + * @return void + */ + public function testConstructorParsesInputsIntoCorrectFields( + $type, + $content, + $extractedType, + $extractedTypes, + $extractedDescription + ) { + $tag = new ThrowsTag($type, $content); + + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($extractedType, $tag->getType()); + $this->assertEquals($extractedTypes, $tag->getTypes()); + $this->assertEquals($extractedDescription, $tag->getDescription()); + } + + /** + * Data provider for testConstructorParsesInputsIntoCorrectFields() + * + * @return array + */ + public function provideDataForConstructor() + { + return array( + array('throws', '', '', array(), ''), + array('throws', 'int', 'int', array('int'), ''), + array( + 'throws', + 'int Number of Bobs', + 'int', + array('int'), + 'Number of Bobs' + ), + array( + 'throws', + 'int|double Number of Bobs', + 'int|double', + array('int', 'double'), + 'Number of Bobs' + ), + array( + 'throws', + "int Number of \n Bobs", + 'int', + array('int'), + "Number of \n Bobs" + ), + array( + 'throws', + " int Number of Bobs", + 'int', + array('int'), + "Number of Bobs" + ) + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php index 5f79d91..45868d7 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php @@ -31,7 +31,7 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase * @param string $exContent * @param string $exReference * - * @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag * @dataProvider provideDataForConstuctor * * @return void diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index c0a1df6..ce471bf 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -149,6 +149,32 @@ DOCBLOCK; ); } + /** + * @covers \phpDocumentor\Reflection\DocBlock::parseTags + * @expectedException \LogicException + * + * @return void + */ + public function testInvalidTagBlock() + { + if (0 == ini_get('allow_url_include')) { + $this->markTestSkipped('"data" URIs for includes are required.'); + } + + require 'data:text/plain;base64,'. base64_encode( +<<<'TAG_HANDLER' +