DocBlockTest.php
9.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* phpDocumentor DocBlock Test
*
* PHP Version 5.3
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Context;
use phpDocumentor\Reflection\DocBlock\Location;
use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
/**
* Test class for phpDocumentor\Reflection\DocBlock
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class DocBlockTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers \phpDocumentor\Reflection\DocBlock
*
* @return void
*/
public function testConstruct()
{
$fixture = <<<DOCBLOCK
/**
* This is a short description
*
* This is a long description
*
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock(
$fixture,
new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')),
new Location(2)
);
$this->assertEquals(
'This is a short description',
$object->getShortDescription()
);
$this->assertEquals(
'This is a long description',
$object->getLongDescription()->getContents()
);
$this->assertCount(2, $object->getTags());
$this->assertTrue($object->hasTag('see'));
$this->assertTrue($object->hasTag('return'));
$this->assertFalse($object->hasTag('category'));
$this->assertSame('MyNamespace', $object->getContext()->getNamespace());
$this->assertSame(
array('PHPDoc' => '\phpDocumentor'),
$object->getContext()->getNamespaceAliases()
);
$this->assertSame(2, $object->getLocation()->getLineNumber());
}
/**
* @covers \phpDocumentor\Reflection\DocBlock::splitDocBlock
*
* @return void
*/
public function testConstructWithTagsOnly()
{
$fixture = <<<DOCBLOCK
/**
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals('', $object->getShortDescription());
$this->assertEquals('', $object->getLongDescription()->getContents());
$this->assertCount(2, $object->getTags());
$this->assertTrue($object->hasTag('see'));
$this->assertTrue($object->hasTag('return'));
$this->assertFalse($object->hasTag('category'));
}
/**
* @covers \phpDocumentor\Reflection\DocBlock::isTemplateStart
*/
public function testIfStartOfTemplateIsDiscovered()
{
$fixture = <<<DOCBLOCK
/**#@+
* @see \MyClass
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals('', $object->getShortDescription());
$this->assertEquals('', $object->getLongDescription()->getContents());
$this->assertCount(2, $object->getTags());
$this->assertTrue($object->hasTag('see'));
$this->assertTrue($object->hasTag('return'));
$this->assertFalse($object->hasTag('category'));
$this->assertTrue($object->isTemplateStart());
}
/**
* @covers \phpDocumentor\Reflection\DocBlock::isTemplateEnd
*/
public function testIfEndOfTemplateIsDiscovered()
{
$fixture = <<<DOCBLOCK
/**#@-*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals('', $object->getShortDescription());
$this->assertEquals('', $object->getLongDescription()->getContents());
$this->assertTrue($object->isTemplateEnd());
}
/**
* @covers \phpDocumentor\Reflection\DocBlock::cleanInput
*
* @return void
*/
public function testConstructOneLiner()
{
$fixture = '/** Short description and nothing more. */';
$object = new DocBlock($fixture);
$this->assertEquals(
'Short description and nothing more.',
$object->getShortDescription()
);
$this->assertEquals('', $object->getLongDescription()->getContents());
$this->assertCount(0, $object->getTags());
}
/**
* @covers \phpDocumentor\Reflection\DocBlock::__construct
*
* @return void
*/
public function testConstructFromReflector()
{
$object = new DocBlock(new \ReflectionClass($this));
$this->assertEquals(
'Test class for phpDocumentor\Reflection\DocBlock',
$object->getShortDescription()
);
$this->assertEquals('', $object->getLongDescription()->getContents());
$this->assertCount(4, $object->getTags());
$this->assertTrue($object->hasTag('author'));
$this->assertTrue($object->hasTag('copyright'));
$this->assertTrue($object->hasTag('license'));
$this->assertTrue($object->hasTag('link'));
$this->assertFalse($object->hasTag('category'));
}
/**
* @expectedException \InvalidArgumentException
*
* @return void
*/
public function testExceptionOnInvalidObject()
{
new DocBlock($this);
}
public function testDotSeperation()
{
$fixture = <<<DOCBLOCK
/**
* This is a short description.
* This is a long description.
* This is a continuation of the long description.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals(
'This is a short description.',
$object->getShortDescription()
);
$this->assertEquals(
"This is a long description.\nThis is a continuation of the long "
."description.",
$object->getLongDescription()->getContents()
);
}
/**
* @covers \phpDocumentor\Reflection\DocBlock::parseTags
* @expectedException \LogicException
*
* @return void
*/
public function testInvalidTagBlock()
{
if (0 == ini_get('allow_url_include')) {
$this->markTestSkipped('"data" URIs for includes are required.');
}
include 'data:text/plain;base64,'. base64_encode(
<<<DOCBLOCK_EXTENSION
<?php
class MyReflectionDocBlock extends \phpDocumentor\Reflection\DocBlock {
protected function splitDocBlock(\$comment) {
return array('', '', 'Invalid tag block');
}
}
DOCBLOCK_EXTENSION
);
new \MyReflectionDocBlock('');
}
public function testTagCaseSensitivity()
{
$fixture = <<<DOCBLOCK
/**
* This is a short description.
*
* This is a long description.
*
* @method null something()
* @Method({"GET", "POST"})
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEquals(
'This is a short description.',
$object->getShortDescription()
);
$this->assertEquals(
'This is a long description.',
$object->getLongDescription()->getContents()
);
$tags = $object->getTags();
$this->assertCount(2, $tags);
$this->assertTrue($object->hasTag('method'));
$this->assertTrue($object->hasTag('Method'));
$this->assertInstanceOf(
__NAMESPACE__ . '\DocBlock\Tag\MethodTag',
$tags[0]
);
$this->assertInstanceOf(
__NAMESPACE__ . '\DocBlock\Tag',
$tags[1]
);
$this->assertNotInstanceOf(
__NAMESPACE__ . '\DocBlock\Tag\MethodTag',
$tags[1]
);
}
/**
* @depends testConstructFromReflector
* @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
*
* @return void
*/
public function testGetTagsByNameZeroAndOneMatch()
{
$object = new DocBlock(new \ReflectionClass($this));
$this->assertEmpty($object->getTagsByName('category'));
$this->assertCount(1, $object->getTagsByName('author'));
}
/**
* @depends testConstructWithTagsOnly
* @covers \phpDocumentor\Reflection\DocBlock::parseTags
*
* @return void
*/
public function testParseMultilineTag()
{
$fixture = <<<DOCBLOCK
/**
* @return void Content on
* multiple lines.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertCount(1, $object->getTags());
}
/**
* @depends testConstructWithTagsOnly
* @covers \phpDocumentor\Reflection\DocBlock::parseTags
*
* @return void
*/
public function testParseMultilineTagWithLineBreaks()
{
$fixture = <<<DOCBLOCK
/**
* @return void Content on
* multiple lines.
*
* One more, after the break.
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertCount(1, $tags = $object->getTags());
/** @var ReturnTag $tag */
$tag = reset($tags);
$this->assertEquals("Content on\n multiple lines.\n\n One more, after the break.", $tag->getDescription());
}
/**
* @depends testConstructWithTagsOnly
* @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
*
* @return void
*/
public function testGetTagsByNameMultipleMatch()
{
$fixture = <<<DOCBLOCK
/**
* @param string
* @param int
* @return void
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertEmpty($object->getTagsByName('category'));
$this->assertCount(1, $object->getTagsByName('return'));
$this->assertCount(2, $object->getTagsByName('param'));
}
}