Minor syntax and doc fixes at Tag::registerTagHandler();

Split the "testTagHandlerRegistration" test into several new ones, with appropriate @covers annotations added;
Although not required for single liners, class names at the built in tag handlers map are indented on a separate line for readability.
This commit is contained in:
Vasil Rangelov
2012-11-11 15:20:59 +02:00
parent 28df2a4cd6
commit bae65d2afe
2 changed files with 108 additions and 24 deletions
+30 -16
View File
@@ -45,22 +45,34 @@ class Tag implements \Reflector
* class.
*/
private static $tagHandlerMappings = array(
'author' => '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
'covers' => '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
'link' => '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
'method' => '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag',
'param' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
'author'
=> '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
'covers'
=> '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
'link'
=> '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
'method'
=> '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag',
'param'
=> '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
'property-read'
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyReadTag',
'property' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag',
'property'
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag',
'property-write'
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyWriteTag',
'return' => '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
'see' => '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
'throw' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
'throws' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
'uses' => '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag',
'var' => '\phpDocumentor\Reflection\DocBlock\Tag\VarTag'
'return'
=> '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
'see'
=> '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
'throw'
=> '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
'throws'
=> '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
'uses'
=> '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag',
'var'
=> '\phpDocumentor\Reflection\DocBlock\Tag\VarTag'
);
/**
@@ -101,7 +113,7 @@ class Tag implements \Reflector
* not available. It must inherit from this class.
*
* @param string $tag Name of tag to regiser a handler for.
* @param string $handler FQCN of handler. Specifing NULL removes the
* @param string|null $handler FQCN of handler. Specifing NULL removes the
* handler for the specified tag, if any.
*
* @return bool TRUE on success, FALSE on failure.
@@ -109,19 +121,21 @@ class Tag implements \Reflector
final public static function registerTagHandler($tag, $handler)
{
$tag = trim((string)$tag);
if (null === $handler) {
unset(self::$tagHandlerMappings[$tag]);
return true;
}
if ('' !== $tag
&& class_exists($handler, true)
&& is_subclass_of($handler, '\\' . __CLASS__)
&& is_subclass_of($handler, __CLASS__)
) {
self::$tagHandlerMappings[$tag] = $handler;
return true;
} else {
return false;
}
return false;
}
/**
@@ -33,6 +33,11 @@ class TagTest extends \PHPUnit_Framework_TestCase
Tag::createInstance('Invalid tag line');
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testTagHandlerUnregistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
@@ -61,7 +66,12 @@ class TagTest extends \PHPUnit_Framework_TestCase
Tag::registerTagHandler('var', $currentHandler);
}
public function testTagHandlerRegistration()
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testTagHandlerCorrectRegistration()
{
if (0 == ini_get('allow_url_include')) {
$this->markTestSkipped('"data" URIs for includes are required.');
@@ -77,18 +87,14 @@ class TagTest extends \PHPUnit_Framework_TestCase
$tagPreUnreg
);
require 'data:text/plain;base64,'. base64_encode(<<<TAG_HANDLER
require 'data:text/plain;base64,'. base64_encode(
<<<TAG_HANDLER
<?php
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
TAG_HANDLER
);
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
$this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler'));
$this->assertFalse(
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
);
$tagPostUnreg = Tag::createInstance('@var mixed');
$this->assertNotInstanceOf(
@@ -107,6 +113,70 @@ TAG_HANDLER
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testNonExistentTagHandlerRegistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
*
* @return void
*/
public function testIncompatibleTagHandlerRegistration()
{
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
$tagPreReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPreReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPreReg
);
$this->assertFalse(
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
);
$tagPostReg = Tag::createInstance('@var mixed');
$this->assertInstanceOf(
$currentHandler,
$tagPostReg
);
$this->assertInstanceOf(
__NAMESPACE__ . '\Tag',
$tagPostReg
);
}
/**
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
* understand the @var doc block.