Skip to content

Commit bae65d2

Browse files
committed
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.
1 parent 28df2a4 commit bae65d2

File tree

2 files changed

+108
-24
lines changed
  • src/phpDocumentor/Reflection/DocBlock
  • tests/phpDocumentor/Reflection/DocBlock

2 files changed

+108
-24
lines changed

src/phpDocumentor/Reflection/DocBlock/Tag.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,34 @@ class Tag implements \Reflector
4545
* class.
4646
*/
4747
private static $tagHandlerMappings = array(
48-
'author' => '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
49-
'covers' => '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
50-
'link' => '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
51-
'method' => '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag',
52-
'param' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
48+
'author'
49+
=> '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag',
50+
'covers'
51+
=> '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag',
52+
'link'
53+
=> '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag',
54+
'method'
55+
=> '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag',
56+
'param'
57+
=> '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
5358
'property-read'
5459
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyReadTag',
55-
'property' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag',
60+
'property'
61+
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag',
5662
'property-write'
5763
=> '\phpDocumentor\Reflection\DocBlock\Tag\PropertyWriteTag',
58-
'return' => '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
59-
'see' => '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
60-
'throw' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
61-
'throws' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
62-
'uses' => '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag',
63-
'var' => '\phpDocumentor\Reflection\DocBlock\Tag\VarTag'
64+
'return'
65+
=> '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag',
66+
'see'
67+
=> '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag',
68+
'throw'
69+
=> '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
70+
'throws'
71+
=> '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag',
72+
'uses'
73+
=> '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag',
74+
'var'
75+
=> '\phpDocumentor\Reflection\DocBlock\Tag\VarTag'
6476
);
6577

6678
/**
@@ -100,28 +112,30 @@ final public static function createInstance($tag_line)
100112
* Registers a handler for tags. The class specified is autoloaded if it's
101113
* not available. It must inherit from this class.
102114
*
103-
* @param string $tag Name of tag to regiser a handler for.
104-
* @param string $handler FQCN of handler. Specifing NULL removes the
115+
* @param string $tag Name of tag to regiser a handler for.
116+
* @param string|null $handler FQCN of handler. Specifing NULL removes the
105117
* handler for the specified tag, if any.
106118
*
107119
* @return bool TRUE on success, FALSE on failure.
108120
*/
109121
final public static function registerTagHandler($tag, $handler)
110122
{
111123
$tag = trim((string)$tag);
124+
112125
if (null === $handler) {
113126
unset(self::$tagHandlerMappings[$tag]);
114127
return true;
115128
}
129+
116130
if ('' !== $tag
117131
&& class_exists($handler, true)
118-
&& is_subclass_of($handler, '\\' . __CLASS__)
132+
&& is_subclass_of($handler, __CLASS__)
119133
) {
120134
self::$tagHandlerMappings[$tag] = $handler;
121135
return true;
122-
} else {
123-
return false;
124136
}
137+
138+
return false;
125139
}
126140

127141
/**

tests/phpDocumentor/Reflection/DocBlock/TagTest.php

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function testInvalidTagLine()
3333
Tag::createInstance('Invalid tag line');
3434
}
3535

36+
/**
37+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
38+
*
39+
* @return void
40+
*/
3641
public function testTagHandlerUnregistration()
3742
{
3843
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
@@ -61,7 +66,12 @@ public function testTagHandlerUnregistration()
6166
Tag::registerTagHandler('var', $currentHandler);
6267
}
6368

64-
public function testTagHandlerRegistration()
69+
/**
70+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
71+
*
72+
* @return void
73+
*/
74+
public function testTagHandlerCorrectRegistration()
6575
{
6676
if (0 == ini_get('allow_url_include')) {
6777
$this->markTestSkipped('"data" URIs for includes are required.');
@@ -77,18 +87,14 @@ public function testTagHandlerRegistration()
7787
$tagPreUnreg
7888
);
7989

80-
require 'data:text/plain;base64,'. base64_encode(<<<TAG_HANDLER
90+
require 'data:text/plain;base64,'. base64_encode(
91+
<<<TAG_HANDLER
8192
<?php
8293
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
8394
TAG_HANDLER
8495
);
8596

86-
87-
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
8897
$this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler'));
89-
$this->assertFalse(
90-
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
91-
);
9298

9399
$tagPostUnreg = Tag::createInstance('@var mixed');
94100
$this->assertNotInstanceOf(
@@ -107,6 +113,70 @@ class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
107113
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
108114
}
109115

116+
/**
117+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
118+
*
119+
* @return void
120+
*/
121+
public function testNonExistentTagHandlerRegistration()
122+
{
123+
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
124+
$tagPreReg = Tag::createInstance('@var mixed');
125+
$this->assertInstanceOf(
126+
$currentHandler,
127+
$tagPreReg
128+
);
129+
$this->assertInstanceOf(
130+
__NAMESPACE__ . '\Tag',
131+
$tagPreReg
132+
);
133+
134+
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
135+
136+
$tagPostReg = Tag::createInstance('@var mixed');
137+
$this->assertInstanceOf(
138+
$currentHandler,
139+
$tagPostReg
140+
);
141+
$this->assertInstanceOf(
142+
__NAMESPACE__ . '\Tag',
143+
$tagPostReg
144+
);
145+
}
146+
147+
/**
148+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
149+
*
150+
* @return void
151+
*/
152+
public function testIncompatibleTagHandlerRegistration()
153+
{
154+
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
155+
$tagPreReg = Tag::createInstance('@var mixed');
156+
$this->assertInstanceOf(
157+
$currentHandler,
158+
$tagPreReg
159+
);
160+
$this->assertInstanceOf(
161+
__NAMESPACE__ . '\Tag',
162+
$tagPreReg
163+
);
164+
165+
$this->assertFalse(
166+
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
167+
);
168+
169+
$tagPostReg = Tag::createInstance('@var mixed');
170+
$this->assertInstanceOf(
171+
$currentHandler,
172+
$tagPostReg
173+
);
174+
$this->assertInstanceOf(
175+
__NAMESPACE__ . '\Tag',
176+
$tagPostReg
177+
);
178+
}
179+
110180
/**
111181
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
112182
* understand the @var doc block.

0 commit comments

Comments
 (0)