Added tests related to the namespaced tag support;

Restored ReturnTag::getTypesCollection() to "protected", to avoid potential BC breaks later.
This commit is contained in:
Vasil Rangelov
2012-11-22 01:23:31 +02:00
parent 7a03741e0b
commit beb96a487b
4 changed files with 106 additions and 20 deletions
@@ -61,8 +61,7 @@ class ReturnTag extends Tag
*/ */
public function getTypes() public function getTypes()
{ {
$this->refreshTypes(); return $this->getTypesCollection()->getArrayCopy();
return $this->types->getArrayCopy();
} }
/** /**
@@ -72,16 +71,15 @@ class ReturnTag extends Tag
*/ */
public function getType() public function getType()
{ {
$this->refreshTypes(); return (string) $this->getTypesCollection();
return (string) $this->types;
} }
/** /**
* Parses the type, if needed. * Returns the type collection.
* *
* @return void * @return void
*/ */
protected function refreshTypes() protected function getTypesCollection()
{ {
if (null === $this->types) { if (null === $this->types) {
$this->types = new Collection( $this->types = new Collection(
@@ -89,5 +87,6 @@ class ReturnTag extends Tag
$this->docblock ? $this->docblock->getContext() : null $this->docblock ? $this->docblock->getContext() : null
); );
} }
return $this->types;
} }
} }
@@ -32,9 +32,7 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase
* @param string $extractedTypes * @param string $extractedTypes
* @param string $extractedDescription * @param string $extractedDescription
* *
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getType
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes
* *
* @dataProvider provideDataForConstructor * @dataProvider provideDataForConstructor
* *
@@ -12,6 +12,9 @@
namespace phpDocumentor\Reflection\DocBlock; namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
/** /**
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag * Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
* *
@@ -77,42 +80,122 @@ class TagTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('"data" URIs for includes are required.'); $this->markTestSkipped('"data" URIs for includes are required.');
} }
$currentHandler = __NAMESPACE__ . '\Tag\VarTag'; $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreUnreg = Tag::createInstance('@var mixed'); $tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf( $this->assertInstanceOf(
$currentHandler, $currentHandler,
$tagPreUnreg $tagPreReg
); );
$this->assertInstanceOf( $this->assertInstanceOf(
__NAMESPACE__ . '\Tag', __NAMESPACE__ . '\Tag',
$tagPreUnreg $tagPreReg
); );
require 'data:text/plain;base64,'. base64_encode( require 'data:text/plain;base64,'. base64_encode(
<<<TAG_HANDLER <<<TAG_HANDLER
<?php <?php
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {} class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
TAG_HANDLER TAG_HANDLER
); );
$this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler')); $this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
$tagPostUnreg = Tag::createInstance('@var mixed'); $tagPostReg = Tag::createInstance('@var mixed');
$this->assertNotInstanceOf( $this->assertNotInstanceOf(
$currentHandler, $currentHandler,
$tagPostUnreg $tagPostReg
); );
$this->assertInstanceOf( $this->assertInstanceOf(
__NAMESPACE__ . '\Tag', __NAMESPACE__ . '\Tag',
$tagPostUnreg $tagPostReg
); );
$this->assertInstanceOf( $this->assertInstanceOf(
'\MyVarHandler', '\MyTagHandler',
$tagPostUnreg $tagPostReg
); );
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler)); $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 * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
* *
@@ -13,6 +13,7 @@
namespace phpDocumentor\Reflection; namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Context; use phpDocumentor\Reflection\DocBlock\Context;
use phpDocumentor\Reflection\DocBlock\Location;
/** /**
* Test class for phpDocumentor\Reflection\DocBlock * Test class for phpDocumentor\Reflection\DocBlock
@@ -24,6 +25,9 @@ use phpDocumentor\Reflection\DocBlock\Context;
*/ */
class DocBlockTest extends \PHPUnit_Framework_TestCase class DocBlockTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @covers \phpDocumentor\Reflection\DocBlock
*/
public function testConstruct() public function testConstruct()
{ {
$fixture = <<<DOCBLOCK $fixture = <<<DOCBLOCK
@@ -38,7 +42,8 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase
DOCBLOCK; DOCBLOCK;
$object = new DocBlock( $object = new DocBlock(
$fixture, $fixture,
new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')) new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')),
new Location(2)
); );
$this->assertEquals( $this->assertEquals(
'This is a short description.', 'This is a short description.',
@@ -58,6 +63,7 @@ DOCBLOCK;
array('PHPDoc' => '\phpDocumentor'), array('PHPDoc' => '\phpDocumentor'),
$object->getContext()->getNamespaceAliases() $object->getContext()->getNamespaceAliases()
); );
$this->assertSame(2, $object->getLocation()->getLineNumber());
} }
/** /**