1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Reflection; |
14
|
|
|
|
15
|
|
|
use Mockery as m; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; |
17
|
|
|
use phpDocumentor\Reflection\Types\Context; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @coversDefaultClass phpDocumentor\Reflection\DocBlock |
22
|
|
|
* @covers ::<private> |
23
|
|
|
* @uses \Webmozart\Assert\Assert |
24
|
|
|
*/ |
25
|
|
|
class DocBlockTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Call Mockery::close after each test. |
29
|
|
|
*/ |
30
|
|
|
public function tearDown() |
31
|
|
|
{ |
32
|
|
|
m::close(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @covers ::__construct |
37
|
|
|
* @covers ::getSummary |
38
|
|
|
* |
39
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
40
|
|
|
*/ |
41
|
|
|
public function testDocBlockCanHaveASummary() |
42
|
|
|
{ |
43
|
|
|
$summary = 'This is a summary'; |
44
|
|
|
|
45
|
|
|
$fixture = new DocBlock($summary); |
46
|
|
|
|
47
|
|
|
$this->assertSame($summary, $fixture->getSummary()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers ::__construct |
52
|
|
|
* |
53
|
|
|
* @expectedException \InvalidArgumentException |
54
|
|
|
*/ |
55
|
|
|
public function testExceptionIsThrownIfSummaryIsNotAString() |
56
|
|
|
{ |
57
|
|
|
new DocBlock([]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @covers ::__construct |
62
|
|
|
* |
63
|
|
|
* @expectedException \InvalidArgumentException |
64
|
|
|
*/ |
65
|
|
|
public function testExceptionIsThrownIfTemplateStartIsNotABoolean() |
66
|
|
|
{ |
67
|
|
|
new DocBlock('', null, [], null, null, ['is not boolean']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @covers ::__construct |
72
|
|
|
* |
73
|
|
|
* @expectedException \InvalidArgumentException |
74
|
|
|
*/ |
75
|
|
|
public function testExceptionIsThrownIfTemplateEndIsNotABoolean() |
76
|
|
|
{ |
77
|
|
|
new DocBlock('', null, [], null, null, false, ['is not boolean']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @covers ::__construct |
82
|
|
|
* @covers ::getDescription |
83
|
|
|
* |
84
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
85
|
|
|
*/ |
86
|
|
|
public function testDocBlockCanHaveADescription() |
87
|
|
|
{ |
88
|
|
|
$description = new DocBlock\Description(''); |
89
|
|
|
|
90
|
|
|
$fixture = new DocBlock('', $description); |
91
|
|
|
|
92
|
|
|
$this->assertSame($description, $fixture->getDescription()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @covers ::__construct |
97
|
|
|
* @covers ::getTags |
98
|
|
|
* |
99
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
100
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
101
|
|
|
*/ |
102
|
|
|
public function testDocBlockCanHaveTags() |
103
|
|
|
{ |
104
|
|
|
$tags = [ |
105
|
|
|
m::mock(DocBlock\Tag::class) |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
$fixture = new DocBlock('', null, $tags); |
109
|
|
|
|
110
|
|
|
$this->assertSame($tags, $fixture->getTags()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @covers ::__construct |
115
|
|
|
* @covers ::getTags |
116
|
|
|
* |
117
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
118
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
119
|
|
|
* |
120
|
|
|
* @expectedException \InvalidArgumentException |
121
|
|
|
*/ |
122
|
|
|
public function testDocBlockAllowsOnlyTags() |
123
|
|
|
{ |
124
|
|
|
$tags = [ |
125
|
|
|
null |
126
|
|
|
]; |
127
|
|
|
|
128
|
|
|
$fixture = new DocBlock('', null, $tags); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @covers ::__construct |
133
|
|
|
* @covers ::getTagsByName |
134
|
|
|
* |
135
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock::getTags |
136
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
137
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
138
|
|
|
*/ |
139
|
|
|
public function testFindTagsInDocBlockByName() |
140
|
|
|
{ |
141
|
|
|
$tag1 = m::mock(DocBlock\Tag::class); |
142
|
|
|
$tag2 = m::mock(DocBlock\Tag::class); |
143
|
|
|
$tag3 = m::mock(DocBlock\Tag::class); |
144
|
|
|
$tags = [$tag1, $tag2, $tag3]; |
145
|
|
|
|
146
|
|
|
$tag1->shouldReceive('getName')->andReturn('abc'); |
147
|
|
|
$tag2->shouldReceive('getName')->andReturn('abcd'); |
148
|
|
|
$tag3->shouldReceive('getName')->andReturn('ab'); |
149
|
|
|
|
150
|
|
|
$fixture = new DocBlock('', null, $tags); |
151
|
|
|
|
152
|
|
|
$this->assertSame([$tag2], $fixture->getTagsByName('abcd')); |
153
|
|
|
$this->assertSame([], $fixture->getTagsByName('Ebcd')); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @covers ::__construct |
158
|
|
|
* @covers ::getTagsByName |
159
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
160
|
|
|
* @expectedException \InvalidArgumentException |
161
|
|
|
*/ |
162
|
|
|
public function testExceptionIsThrownIfNameForTagsIsNotString() |
163
|
|
|
{ |
164
|
|
|
$fixture = new DocBlock(); |
165
|
|
|
$fixture->getTagsByName([]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @covers ::__construct |
170
|
|
|
* @covers ::hasTag |
171
|
|
|
* |
172
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock::getTags |
173
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
174
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
175
|
|
|
*/ |
176
|
|
|
public function testCheckIfThereAreTagsWithAGivenName() |
177
|
|
|
{ |
178
|
|
|
$tag1 = m::mock(DocBlock\Tag::class); |
179
|
|
|
$tag2 = m::mock(DocBlock\Tag::class); |
180
|
|
|
$tag3 = m::mock(DocBlock\Tag::class); |
181
|
|
|
$tags = [$tag1, $tag2, $tag3]; |
182
|
|
|
|
183
|
|
|
$tag1->shouldReceive('getName')->twice()->andReturn('abc'); |
184
|
|
|
$tag2->shouldReceive('getName')->twice()->andReturn('abcd'); |
185
|
|
|
$tag3->shouldReceive('getName')->once(); |
186
|
|
|
|
187
|
|
|
$fixture = new DocBlock('', null, $tags); |
188
|
|
|
|
189
|
|
|
$this->assertTrue($fixture->hasTag('abcd')); |
190
|
|
|
$this->assertFalse($fixture->hasTag('Ebcd')); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @covers ::__construct |
195
|
|
|
* @covers ::hasTag |
196
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
197
|
|
|
* @expectedException \InvalidArgumentException |
198
|
|
|
*/ |
199
|
|
|
public function testExceptionIsThrownIfNameForCheckingTagsIsNotString() |
200
|
|
|
{ |
201
|
|
|
$fixture = new DocBlock(); |
202
|
|
|
$fixture->hasTag([]); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @covers ::__construct |
207
|
|
|
* @covers ::getContext |
208
|
|
|
* |
209
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
210
|
|
|
* @uses \phpDocumentor\Reflection\Types\Context |
211
|
|
|
*/ |
212
|
|
|
public function testDocBlockKnowsInWhichNamespaceItIsAndWhichAliasesThereAre() |
213
|
|
|
{ |
214
|
|
|
$context = new Context(''); |
215
|
|
|
|
216
|
|
|
$fixture = new DocBlock('', null, [], $context); |
217
|
|
|
|
218
|
|
|
$this->assertSame($context, $fixture->getContext()); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @covers ::__construct |
223
|
|
|
* @covers ::getLocation |
224
|
|
|
* |
225
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
226
|
|
|
* @uses \phpDocumentor\Reflection\Location |
227
|
|
|
*/ |
228
|
|
|
public function testDocBlockKnowsAtWhichLineItIs() |
229
|
|
|
{ |
230
|
|
|
$location = new Location(10); |
231
|
|
|
|
232
|
|
|
$fixture = new DocBlock('', null, [], null, $location); |
233
|
|
|
|
234
|
|
|
$this->assertSame($location, $fixture->getLocation()); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @covers ::__construct |
239
|
|
|
* @covers ::isTemplateStart |
240
|
|
|
* |
241
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
242
|
|
|
*/ |
243
|
|
|
public function testDocBlockKnowsIfItIsTheStartOfADocBlockTemplate() |
244
|
|
|
{ |
245
|
|
|
$fixture = new DocBlock('', null, [], null, null, true); |
246
|
|
|
|
247
|
|
|
$this->assertTrue($fixture->isTemplateStart()); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @covers ::__construct |
252
|
|
|
* @covers ::isTemplateEnd |
253
|
|
|
* |
254
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
255
|
|
|
*/ |
256
|
|
|
public function testDocBlockKnowsIfItIsTheEndOfADocBlockTemplate() |
257
|
|
|
{ |
258
|
|
|
$fixture = new DocBlock('', null, [], null, null, false, true); |
259
|
|
|
|
260
|
|
|
$this->assertTrue($fixture->isTemplateEnd()); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @covers ::__construct |
265
|
|
|
* @covers ::removeTag |
266
|
|
|
* |
267
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated |
268
|
|
|
*/ |
269
|
|
|
public function testRemoveTag() |
270
|
|
|
{ |
271
|
|
|
$someTag = new Deprecated(); |
272
|
|
|
$anotherTag = new Deprecated(); |
273
|
|
|
|
274
|
|
|
$fixture = new DocBlock('', null, [$someTag]); |
275
|
|
|
|
276
|
|
|
$this->assertCount(1, $fixture->getTags()); |
277
|
|
|
|
278
|
|
|
$fixture->removeTag($anotherTag); |
279
|
|
|
|
280
|
|
|
$this->assertCount(1, $fixture->getTags()); |
281
|
|
|
|
282
|
|
|
$fixture->removeTag($someTag); |
283
|
|
|
|
284
|
|
|
$this->assertCount(0, $fixture->getTags()); |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|