From bf3e86788d29c357a071cc81a78062a408e461ef Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Thu, 22 Nov 2012 01:23:31 +0200 Subject: [PATCH] Added tests related to the namespaced tag support; Restored ReturnTag::getTypesCollection() to "protected", to avoid potential BC breaks later. --- .../Reflection/DocBlock/Tag/ReturnTag.php | 11 +- .../Reflection/DocBlock/Tag/ReturnTagTest.php | 4 +- .../Reflection/DocBlock/TagTest.php | 103 ++++++++++++++++-- .../phpDocumentor/Reflection/DocBlockTest.php | 8 +- 4 files changed, 106 insertions(+), 20 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php index 8690727..d903778 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -61,8 +61,7 @@ class ReturnTag extends Tag */ public function getTypes() { - $this->refreshTypes(); - return $this->types->getArrayCopy(); + return $this->getTypesCollection()->getArrayCopy(); } /** @@ -72,16 +71,15 @@ class ReturnTag extends Tag */ public function getType() { - $this->refreshTypes(); - return (string) $this->types; + return (string) $this->getTypesCollection(); } /** - * Parses the type, if needed. + * Returns the type collection. * * @return void */ - protected function refreshTypes() + protected function getTypesCollection() { if (null === $this->types) { $this->types = new Collection( @@ -89,5 +87,6 @@ class ReturnTag extends Tag $this->docblock ? $this->docblock->getContext() : null ); } + return $this->types; } } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php index df43299..fcbfc64 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -32,9 +32,7 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase * @param string $extractedTypes * @param string $extractedDescription * - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getType - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag * * @dataProvider provideDataForConstructor * diff --git a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php index cd77acf..9307bfd 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php @@ -12,6 +12,9 @@ namespace phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Context; + /** * Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag * @@ -77,41 +80,121 @@ class TagTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('"data" URIs for includes are required.'); } $currentHandler = __NAMESPACE__ . '\Tag\VarTag'; - $tagPreUnreg = Tag::createInstance('@var mixed'); + $tagPreReg = Tag::createInstance('@var mixed'); $this->assertInstanceOf( $currentHandler, - $tagPreUnreg + $tagPreReg ); $this->assertInstanceOf( __NAMESPACE__ . '\Tag', - $tagPreUnreg + $tagPreReg ); require 'data:text/plain;base64,'. base64_encode( <<assertTrue(Tag::registerTagHandler('var', '\MyVarHandler')); + $this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler')); - $tagPostUnreg = Tag::createInstance('@var mixed'); + $tagPostReg = Tag::createInstance('@var mixed'); $this->assertNotInstanceOf( $currentHandler, - $tagPostUnreg + $tagPostReg ); $this->assertInstanceOf( __NAMESPACE__ . '\Tag', - $tagPostUnreg + $tagPostReg ); $this->assertInstanceOf( - '\MyVarHandler', - $tagPostUnreg + '\MyTagHandler', + $tagPostReg ); $this->assertTrue(Tag::registerTagHandler('var', $currentHandler)); } + + /** + * @depends testTagHandlerCorrectRegistration + * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler + * @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance + */ + public function testNamespacedTagHandlerCorrectRegistration() + { + $tagPreReg = Tag::createInstance('@T something'); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPreReg + ); + $this->assertNotInstanceOf( + '\MyTagHandler', + $tagPreReg + ); + + $this->assertTrue( + Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler') + ); + + $tagPostReg = Tag::createInstance( + '@T something', + new DocBlock( + '', + new Context('', array('T' => '\MyNamespace\MyTag')) + ) + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPostReg + ); + $this->assertInstanceOf( + '\MyTagHandler', + $tagPostReg + ); + + $this->assertTrue( + Tag::registerTagHandler('\MyNamespace\MyTag', null) + ); + } + + /** + * @depends testTagHandlerCorrectRegistration + * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler + * @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance + */ + public function testNamespacedTagHandlerIncorrectRegistration() + { + $tagPreReg = Tag::createInstance('@T something'); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPreReg + ); + $this->assertNotInstanceOf( + '\MyTagHandler', + $tagPreReg + ); + + $this->assertFalse( + Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler') + ); + + $tagPostReg = Tag::createInstance( + '@T something', + new DocBlock( + '', + new Context('', array('T' => '\MyNamespace\MyTag')) + ) + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPostReg + ); + $this->assertNotInstanceOf( + '\MyTagHandler', + $tagPostReg + ); + } /** * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index c7b9ab9..351ace4 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -13,6 +13,7 @@ namespace phpDocumentor\Reflection; use phpDocumentor\Reflection\DocBlock\Context; +use phpDocumentor\Reflection\DocBlock\Location; /** * Test class for phpDocumentor\Reflection\DocBlock @@ -24,6 +25,9 @@ use phpDocumentor\Reflection\DocBlock\Context; */ class DocBlockTest extends \PHPUnit_Framework_TestCase { + /** + * @covers \phpDocumentor\Reflection\DocBlock + */ public function testConstruct() { $fixture = << '\phpDocumentor')) + new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')), + new Location(2) ); $this->assertEquals( 'This is a short description.', @@ -58,6 +63,7 @@ DOCBLOCK; array('PHPDoc' => '\phpDocumentor'), $object->getContext()->getNamespaceAliases() ); + $this->assertSame(2, $object->getLocation()->getLineNumber()); } /**