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