1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of phpDocumentor. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
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
|
|
|
* @coversDefaultClass phpDocumentor\Reflection\DocBlock |
23
|
|
|
* @covers ::<private> |
24
|
|
|
* @uses \Webmozart\Assert\Assert |
25
|
|
|
*/ |
26
|
|
|
class DocBlockTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Call Mockery::close after each test. |
30
|
|
|
*/ |
31
|
|
|
public function tearDown(): void |
32
|
|
|
{ |
33
|
|
|
m::close(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @covers ::__construct |
38
|
|
|
* @covers ::getSummary |
39
|
|
|
* |
40
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
41
|
|
|
*/ |
42
|
|
|
public function testDocBlockCanHaveASummary(): void |
43
|
|
|
{ |
44
|
|
|
$summary = 'This is a summary'; |
45
|
|
|
|
46
|
|
|
$fixture = new DocBlock($summary); |
47
|
|
|
|
48
|
|
|
$this->assertSame($summary, $fixture->getSummary()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers ::__construct |
53
|
|
|
* @covers ::getSummary |
54
|
|
|
* |
55
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
56
|
|
|
*/ |
57
|
|
|
public function testDocBlockCanHaveEllipsisInSummary(): void |
58
|
|
|
{ |
59
|
|
|
$summary = 'This is a short (...) description.'; |
60
|
|
|
|
61
|
|
|
$fixture = new DocBlock($summary); |
62
|
|
|
|
63
|
|
|
$this->assertSame($summary, $fixture->getSummary()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @covers ::__construct |
68
|
|
|
* @covers ::getDescription |
69
|
|
|
* |
70
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
71
|
|
|
*/ |
72
|
|
|
public function testDocBlockCanHaveADescription(): void |
73
|
|
|
{ |
74
|
|
|
$description = new DocBlock\Description(''); |
75
|
|
|
|
76
|
|
|
$fixture = new DocBlock('', $description); |
77
|
|
|
|
78
|
|
|
$this->assertSame($description, $fixture->getDescription()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @covers ::__construct |
83
|
|
|
* @covers ::getTags |
84
|
|
|
* |
85
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
86
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
87
|
|
|
*/ |
88
|
|
|
public function testDocBlockCanHaveTags(): void |
89
|
|
|
{ |
90
|
|
|
$tags = [ |
91
|
|
|
m::mock(DocBlock\Tag::class), |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
$fixture = new DocBlock('', null, $tags); |
95
|
|
|
|
96
|
|
|
$this->assertSame($tags, $fixture->getTags()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @covers ::__construct |
101
|
|
|
* @covers ::getTags |
102
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
103
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
104
|
|
|
*/ |
105
|
|
|
public function testDocBlockAllowsOnlyTags(): void |
106
|
|
|
{ |
107
|
|
|
$this->expectException('InvalidArgumentException'); |
108
|
|
|
$tags = [ |
109
|
|
|
null, |
110
|
|
|
]; |
111
|
|
|
$fixture = new DocBlock('', null, $tags); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @covers ::__construct |
116
|
|
|
* @covers ::getTagsByName |
117
|
|
|
* |
118
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock::getTags |
119
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
120
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
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
|
|
|
* @covers ::__construct |
141
|
|
|
* @covers ::hasTag |
142
|
|
|
* |
143
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock::getTags |
144
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
145
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tag |
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
|
|
|
* @covers ::__construct |
166
|
|
|
* @covers ::getContext |
167
|
|
|
* |
168
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
169
|
|
|
* @uses \phpDocumentor\Reflection\Types\Context |
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
|
|
|
* @covers ::__construct |
182
|
|
|
* @covers ::getLocation |
183
|
|
|
* |
184
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
185
|
|
|
* @uses \phpDocumentor\Reflection\Location |
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
|
|
|
* @covers ::__construct |
198
|
|
|
* @covers ::isTemplateStart |
199
|
|
|
* |
200
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
201
|
|
|
*/ |
202
|
|
|
public function testDocBlockKnowsIfItIsTheStartOfADocBlockTemplate(): void |
203
|
|
|
{ |
204
|
|
|
$fixture = new DocBlock('', null, [], null, null, true); |
205
|
|
|
|
206
|
|
|
$this->assertTrue($fixture->isTemplateStart()); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @covers ::__construct |
211
|
|
|
* @covers ::isTemplateEnd |
212
|
|
|
* |
213
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
214
|
|
|
*/ |
215
|
|
|
public function testDocBlockKnowsIfItIsTheEndOfADocBlockTemplate(): void |
216
|
|
|
{ |
217
|
|
|
$fixture = new DocBlock('', null, [], null, null, false, true); |
218
|
|
|
|
219
|
|
|
$this->assertTrue($fixture->isTemplateEnd()); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @covers ::__construct |
224
|
|
|
* @covers ::removeTag |
225
|
|
|
* |
226
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated |
227
|
|
|
*/ |
228
|
|
|
public function testRemoveTag(): void |
229
|
|
|
{ |
230
|
|
|
$someTag = new Deprecated(); |
231
|
|
|
$anotherTag = new Deprecated(); |
232
|
|
|
|
233
|
|
|
$fixture = new DocBlock('', null, [$someTag]); |
234
|
|
|
|
235
|
|
|
$this->assertCount(1, $fixture->getTags()); |
236
|
|
|
|
237
|
|
|
$fixture->removeTag($anotherTag); |
238
|
|
|
|
239
|
|
|
$this->assertCount(1, $fixture->getTags()); |
240
|
|
|
|
241
|
|
|
$fixture->removeTag($someTag); |
242
|
|
|
|
243
|
|
|
$this->assertCount(0, $fixture->getTags()); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|