Skip to content

Commit beb96a4

Browse files
committed
Added tests related to the namespaced tag support;
Restored ReturnTag::getTypesCollection() to "protected", to avoid potential BC breaks later.
1 parent 7a03741 commit beb96a4

File tree

4 files changed

+106
-20
lines changed

4 files changed

+106
-20
lines changed

src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public function __construct(
6161
*/
6262
public function getTypes()
6363
{
64-
$this->refreshTypes();
65-
return $this->types->getArrayCopy();
64+
return $this->getTypesCollection()->getArrayCopy();
6665
}
6766

6867
/**
@@ -72,22 +71,22 @@ public function getTypes()
7271
*/
7372
public function getType()
7473
{
75-
$this->refreshTypes();
76-
return (string) $this->types;
74+
return (string) $this->getTypesCollection();
7775
}
7876

7977
/**
80-
* Parses the type, if needed.
78+
* Returns the type collection.
8179
*
8280
* @return void
8381
*/
84-
protected function refreshTypes()
82+
protected function getTypesCollection()
8583
{
8684
if (null === $this->types) {
8785
$this->types = new Collection(
8886
array($this->type),
8987
$this->docblock ? $this->docblock->getContext() : null
9088
);
9189
}
90+
return $this->types;
9291
}
9392
}

tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase
3232
* @param string $extractedTypes
3333
* @param string $extractedDescription
3434
*
35-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct
36-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getType
37-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes
35+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag
3836
*
3937
* @dataProvider provideDataForConstructor
4038
*

tests/phpDocumentor/Reflection/DocBlock/TagTest.php

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace phpDocumentor\Reflection\DocBlock;
1414

15+
use phpDocumentor\Reflection\DocBlock;
16+
use phpDocumentor\Reflection\DocBlock\Context;
17+
1518
/**
1619
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
1720
*
@@ -77,41 +80,121 @@ public function testTagHandlerCorrectRegistration()
7780
$this->markTestSkipped('"data" URIs for includes are required.');
7881
}
7982
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
80-
$tagPreUnreg = Tag::createInstance('@var mixed');
83+
$tagPreReg = Tag::createInstance('@var mixed');
8184
$this->assertInstanceOf(
8285
$currentHandler,
83-
$tagPreUnreg
86+
$tagPreReg
8487
);
8588
$this->assertInstanceOf(
8689
__NAMESPACE__ . '\Tag',
87-
$tagPreUnreg
90+
$tagPreReg
8891
);
8992

9093
require 'data:text/plain;base64,'. base64_encode(
9194
<<<TAG_HANDLER
9295
<?php
93-
class MyVarHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
96+
class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
9497
TAG_HANDLER
9598
);
9699

97-
$this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler'));
100+
$this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
98101

99-
$tagPostUnreg = Tag::createInstance('@var mixed');
102+
$tagPostReg = Tag::createInstance('@var mixed');
100103
$this->assertNotInstanceOf(
101104
$currentHandler,
102-
$tagPostUnreg
105+
$tagPostReg
103106
);
104107
$this->assertInstanceOf(
105108
__NAMESPACE__ . '\Tag',
106-
$tagPostUnreg
109+
$tagPostReg
107110
);
108111
$this->assertInstanceOf(
109-
'\MyVarHandler',
110-
$tagPostUnreg
112+
'\MyTagHandler',
113+
$tagPostReg
111114
);
112115

113116
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
114117
}
118+
119+
/**
120+
* @depends testTagHandlerCorrectRegistration
121+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
122+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
123+
*/
124+
public function testNamespacedTagHandlerCorrectRegistration()
125+
{
126+
$tagPreReg = Tag::createInstance('@T something');
127+
$this->assertInstanceOf(
128+
__NAMESPACE__ . '\Tag',
129+
$tagPreReg
130+
);
131+
$this->assertNotInstanceOf(
132+
'\MyTagHandler',
133+
$tagPreReg
134+
);
135+
136+
$this->assertTrue(
137+
Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler')
138+
);
139+
140+
$tagPostReg = Tag::createInstance(
141+
'@T something',
142+
new DocBlock(
143+
'',
144+
new Context('', array('T' => '\MyNamespace\MyTag'))
145+
)
146+
);
147+
$this->assertInstanceOf(
148+
__NAMESPACE__ . '\Tag',
149+
$tagPostReg
150+
);
151+
$this->assertInstanceOf(
152+
'\MyTagHandler',
153+
$tagPostReg
154+
);
155+
156+
$this->assertTrue(
157+
Tag::registerTagHandler('\MyNamespace\MyTag', null)
158+
);
159+
}
160+
161+
/**
162+
* @depends testTagHandlerCorrectRegistration
163+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
164+
* @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
165+
*/
166+
public function testNamespacedTagHandlerIncorrectRegistration()
167+
{
168+
$tagPreReg = Tag::createInstance('@T something');
169+
$this->assertInstanceOf(
170+
__NAMESPACE__ . '\Tag',
171+
$tagPreReg
172+
);
173+
$this->assertNotInstanceOf(
174+
'\MyTagHandler',
175+
$tagPreReg
176+
);
177+
178+
$this->assertFalse(
179+
Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler')
180+
);
181+
182+
$tagPostReg = Tag::createInstance(
183+
'@T something',
184+
new DocBlock(
185+
'',
186+
new Context('', array('T' => '\MyNamespace\MyTag'))
187+
)
188+
);
189+
$this->assertInstanceOf(
190+
__NAMESPACE__ . '\Tag',
191+
$tagPostReg
192+
);
193+
$this->assertNotInstanceOf(
194+
'\MyTagHandler',
195+
$tagPostReg
196+
);
197+
}
115198

116199
/**
117200
* @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler

tests/phpDocumentor/Reflection/DocBlockTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace phpDocumentor\Reflection;
1414

1515
use phpDocumentor\Reflection\DocBlock\Context;
16+
use phpDocumentor\Reflection\DocBlock\Location;
1617

1718
/**
1819
* Test class for phpDocumentor\Reflection\DocBlock
@@ -24,6 +25,9 @@
2425
*/
2526
class DocBlockTest extends \PHPUnit_Framework_TestCase
2627
{
28+
/**
29+
* @covers \phpDocumentor\Reflection\DocBlock
30+
*/
2731
public function testConstruct()
2832
{
2933
$fixture = <<<DOCBLOCK
@@ -38,7 +42,8 @@ public function testConstruct()
3842
DOCBLOCK;
3943
$object = new DocBlock(
4044
$fixture,
41-
new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor'))
45+
new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')),
46+
new Location(2)
4247
);
4348
$this->assertEquals(
4449
'This is a short description.',
@@ -58,6 +63,7 @@ public function testConstruct()
5863
array('PHPDoc' => '\phpDocumentor'),
5964
$object->getContext()->getNamespaceAliases()
6065
);
66+
$this->assertSame(2, $object->getLocation()->getLineNumber());
6167
}
6268

6369
/**

0 commit comments

Comments
 (0)