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 2dbc608a51
commit bf3e86788d
4 changed files with 106 additions and 20 deletions
@@ -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;
}
}
@@ -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
*
@@ -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(
<<<TAG_HANDLER
<?php
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
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(
$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
@@ -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 = <<<DOCBLOCK
@@ -38,7 +42,8 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase
DOCBLOCK;
$object = new DocBlock(
$fixture,
new Context('\MyNamespace', array('PHPDoc' => '\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());
}
/**