mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
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:
@@ -45,22 +45,34 @@ class Tag implements \Reflector
|
|||||||
* class.
|
* class.
|
||||||
*/
|
*/
|
||||||
private static $tagHandlerMappings = array(
|
private static $tagHandlerMappings = array(
|
||||||
'author' => '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
|
'author'
|
||||||
'covers' => '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
|
||||||
'link' => '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
|
'covers'
|
||||||
'method' => '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag',
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
|
||||||
'param' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
|
'link'
|
||||||
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
|
||||||
|
'method'
|
||||||
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag',
|
||||||
|
'param'
|
||||||
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
|
||||||
'property-read'
|
'property-read'
|
||||||
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyReadTag',
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyReadTag',
|
||||||
'property' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag',
|
'property'
|
||||||
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag',
|
||||||
'property-write'
|
'property-write'
|
||||||
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyWriteTag',
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyWriteTag',
|
||||||
'return' => '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
|
'return'
|
||||||
'see' => '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
|
||||||
'throw' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
|
'see'
|
||||||
'throws' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
|
=> '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
|
||||||
'uses' => '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag',
|
'throw'
|
||||||
'var' => '\phpDocumentor\Reflection\DocBlock\Tag\VarTag'
|
=> '\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.
|
* not available. It must inherit from this class.
|
||||||
*
|
*
|
||||||
* @param string $tag Name of tag to regiser a handler for.
|
* @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.
|
* handler for the specified tag, if any.
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE on failure.
|
* @return bool TRUE on success, FALSE on failure.
|
||||||
@@ -109,19 +121,21 @@ class Tag implements \Reflector
|
|||||||
final public static function registerTagHandler($tag, $handler)
|
final public static function registerTagHandler($tag, $handler)
|
||||||
{
|
{
|
||||||
$tag = trim((string)$tag);
|
$tag = trim((string)$tag);
|
||||||
|
|
||||||
if (null === $handler) {
|
if (null === $handler) {
|
||||||
unset(self::$tagHandlerMappings[$tag]);
|
unset(self::$tagHandlerMappings[$tag]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' !== $tag
|
if ('' !== $tag
|
||||||
&& class_exists($handler, true)
|
&& class_exists($handler, true)
|
||||||
&& is_subclass_of($handler, '\\' . __CLASS__)
|
&& is_subclass_of($handler, __CLASS__)
|
||||||
) {
|
) {
|
||||||
self::$tagHandlerMappings[$tag] = $handler;
|
self::$tagHandlerMappings[$tag] = $handler;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ class TagTest extends \PHPUnit_Framework_TestCase
|
|||||||
Tag::createInstance('Invalid tag line');
|
Tag::createInstance('Invalid tag line');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function testTagHandlerUnregistration()
|
public function testTagHandlerUnregistration()
|
||||||
{
|
{
|
||||||
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
|
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
|
||||||
@@ -61,7 +66,12 @@ class TagTest extends \PHPUnit_Framework_TestCase
|
|||||||
Tag::registerTagHandler('var', $currentHandler);
|
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')) {
|
if (0 == ini_get('allow_url_include')) {
|
||||||
$this->markTestSkipped('"data" URIs for includes are required.');
|
$this->markTestSkipped('"data" URIs for includes are required.');
|
||||||
@@ -77,18 +87,14 @@ class TagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tagPreUnreg
|
$tagPreUnreg
|
||||||
);
|
);
|
||||||
|
|
||||||
require 'data:text/plain;base64,'. base64_encode(<<<TAG_HANDLER
|
require 'data:text/plain;base64,'. base64_encode(
|
||||||
|
<<<TAG_HANDLER
|
||||||
<?php
|
<?php
|
||||||
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
|
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
|
||||||
TAG_HANDLER
|
TAG_HANDLER
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
|
|
||||||
$this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler'));
|
$this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler'));
|
||||||
$this->assertFalse(
|
|
||||||
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
$tagPostUnreg = Tag::createInstance('@var mixed');
|
$tagPostUnreg = Tag::createInstance('@var mixed');
|
||||||
$this->assertNotInstanceOf(
|
$this->assertNotInstanceOf(
|
||||||
@@ -107,6 +113,70 @@ TAG_HANDLER
|
|||||||
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
|
$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
|
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
|
||||||
* understand the @var doc block.
|
* understand the @var doc block.
|
||||||
|
|||||||
Reference in New Issue
Block a user