1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DocBlock\Tags; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Example; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Example |
13
|
|
|
* @covers ::<private> |
14
|
|
|
*/ |
15
|
|
|
class ExampleTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
19
|
|
|
* |
20
|
|
|
* @covers ::create |
21
|
|
|
* @covers ::__construct |
22
|
|
|
* @covers ::getContent |
23
|
|
|
*/ |
24
|
|
|
public function testExampleWithoutContent() : void |
25
|
|
|
{ |
26
|
|
|
$tag = Example::create('"example1.php"'); |
27
|
|
|
$this->assertEquals('"example1.php"', $tag->getContent()); |
28
|
|
|
$this->assertEquals('', $tag->getDescription()); |
29
|
|
|
$this->assertEquals('example', $tag->getName()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
34
|
|
|
* |
35
|
|
|
* @covers ::create |
36
|
|
|
* @covers ::__construct |
37
|
|
|
* @covers ::getFilePath |
38
|
|
|
* @covers ::getDescription |
39
|
|
|
*/ |
40
|
|
|
public function testWithDescription() : void |
41
|
|
|
{ |
42
|
|
|
$tag = Example::create('"example1.php" some text'); |
43
|
|
|
$this->assertEquals('example1.php', $tag->getFilePath()); |
44
|
|
|
$this->assertEquals('some text', $tag->getDescription()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
49
|
|
|
* |
50
|
|
|
* @covers ::create |
51
|
|
|
* @covers ::__construct |
52
|
|
|
* @covers ::getFilePath |
53
|
|
|
* @covers ::getStartingLine |
54
|
|
|
*/ |
55
|
|
|
public function testStartlineIsParsed() : void |
56
|
|
|
{ |
57
|
|
|
$tag = Example::create('"example1.php" 10'); |
58
|
|
|
$this->assertEquals('example1.php', $tag->getFilePath()); |
59
|
|
|
$this->assertEquals(10, $tag->getStartingLine()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
64
|
|
|
* |
65
|
|
|
* @covers ::create |
66
|
|
|
* @covers ::__construct |
67
|
|
|
* @covers ::getFilePath |
68
|
|
|
* @covers ::getStartingLine |
69
|
|
|
* @covers ::getDescription |
70
|
|
|
*/ |
71
|
|
|
public function testAllowOmitingLineCount() : void |
72
|
|
|
{ |
73
|
|
|
$tag = Example::create('"example1.php" 10 some text'); |
74
|
|
|
$this->assertEquals('example1.php', $tag->getFilePath()); |
75
|
|
|
$this->assertEquals(10, $tag->getStartingLine()); |
76
|
|
|
$this->assertEquals('some text', $tag->getDescription()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
81
|
|
|
* |
82
|
|
|
* @covers ::create |
83
|
|
|
* @covers ::__construct |
84
|
|
|
* @covers ::getFilePath |
85
|
|
|
* @covers ::getStartingLine |
86
|
|
|
* @covers ::getLineCount |
87
|
|
|
*/ |
88
|
|
|
public function testLengthIsParsed() : void |
89
|
|
|
{ |
90
|
|
|
$tag = Example::create('"example1.php" 10 5'); |
91
|
|
|
$this->assertEquals('example1.php', $tag->getFilePath()); |
92
|
|
|
$this->assertEquals(10, $tag->getStartingLine()); |
93
|
|
|
$this->assertEquals(5, $tag->getLineCount()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
98
|
|
|
* |
99
|
|
|
* @dataProvider tagContentProvider |
100
|
|
|
* @covers ::create |
101
|
|
|
* @covers ::__construct |
102
|
|
|
* @covers ::getFilePath |
103
|
|
|
* @covers ::getStartingLine |
104
|
|
|
* @covers ::getLineCount |
105
|
|
|
* @covers ::getDescription |
106
|
|
|
* @covers ::getContent |
107
|
|
|
*/ |
108
|
|
|
public function testFactoryMethod( |
109
|
|
|
string $input, |
110
|
|
|
string $filePath, |
111
|
|
|
int $startLine, |
112
|
|
|
int $lineCount, |
113
|
|
|
?string $description, |
114
|
|
|
string $content |
115
|
|
|
) : void { |
116
|
|
|
$tag = Example::create($input); |
117
|
|
|
$this->assertSame($filePath, $tag->getFilePath()); |
118
|
|
|
$this->assertSame($startLine, $tag->getStartingLine()); |
119
|
|
|
$this->assertSame($lineCount, $tag->getLineCount()); |
120
|
|
|
$this->assertSame($description, $tag->getDescription()); |
121
|
|
|
$this->assertSame($content, $tag->getContent()); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** @return mixed[][] */ |
125
|
|
|
public function tagContentProvider() : array |
126
|
|
|
{ |
127
|
|
|
return [ |
128
|
|
|
[ |
129
|
|
|
'"example1.php" 10 5 test text ', |
130
|
|
|
'example1.php', |
131
|
|
|
10, |
132
|
|
|
5, |
133
|
|
|
'test text', |
134
|
|
|
'test text', |
135
|
|
|
], |
136
|
|
|
[ |
137
|
|
|
'example1.php 10 5 test text', |
138
|
|
|
'example1.php', |
139
|
|
|
10, |
140
|
|
|
5, |
141
|
|
|
'test text', |
142
|
|
|
'test text', |
143
|
|
|
], |
144
|
|
|
[ |
145
|
|
|
'example1.php 1 10 test text', |
146
|
|
|
'example1.php', |
147
|
|
|
1, |
148
|
|
|
10, |
149
|
|
|
'test text', |
150
|
|
|
'test text', |
151
|
|
|
], |
152
|
|
|
[ |
153
|
|
|
'example1.php', |
154
|
|
|
'example1.php', |
155
|
|
|
1, |
156
|
|
|
0, |
157
|
|
|
null, |
158
|
|
|
'example1.php', |
159
|
|
|
], |
160
|
|
|
[ |
161
|
|
|
'file://example1.php ', |
162
|
|
|
'file://example1.php', |
163
|
|
|
1, |
164
|
|
|
0, |
165
|
|
|
'', |
166
|
|
|
'file://example1.php', |
167
|
|
|
], |
168
|
|
|
[ |
169
|
|
|
'/example1.php', |
170
|
|
|
'/example1.php', |
171
|
|
|
1, |
172
|
|
|
0, |
173
|
|
|
null, |
174
|
|
|
'/example1.php', |
175
|
|
|
], |
176
|
|
|
]; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @dataProvider invalidExampleProvider |
181
|
|
|
* @covers ::__construct |
182
|
|
|
*/ |
183
|
|
|
public function testValidatesArguments( |
184
|
|
|
string $filePath, |
185
|
|
|
bool $isUrl, |
186
|
|
|
int $startLine, |
187
|
|
|
int $lineCount, |
188
|
|
|
string $description |
189
|
|
|
) : void { |
190
|
|
|
$this->expectException(InvalidArgumentException::class); |
191
|
|
|
|
192
|
|
|
new Example( |
193
|
|
|
$filePath, |
194
|
|
|
$isUrl, |
195
|
|
|
$startLine, |
196
|
|
|
$lineCount, |
197
|
|
|
$description |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** @return mixed[][] */ |
202
|
|
|
public function invalidExampleProvider() : array |
203
|
|
|
{ |
204
|
|
|
return [ |
205
|
|
|
'invalid start' => [ |
206
|
|
|
'/some/path', |
207
|
|
|
false, |
208
|
|
|
-1, |
209
|
|
|
0, |
210
|
|
|
'text', |
211
|
|
|
], |
212
|
|
|
'invalid start 2' => [ |
213
|
|
|
'/some/path', |
214
|
|
|
false, |
215
|
|
|
-10, |
216
|
|
|
0, |
217
|
|
|
'text', |
218
|
|
|
], |
219
|
|
|
'invalid length' => [ |
220
|
|
|
'/some/path', |
221
|
|
|
false, |
222
|
|
|
1, |
223
|
|
|
-1, |
224
|
|
|
'text', |
225
|
|
|
], |
226
|
|
|
'invalid length 2' => [ |
227
|
|
|
'/some/path', |
228
|
|
|
false, |
229
|
|
|
1, |
230
|
|
|
-10, |
231
|
|
|
'text', |
232
|
|
|
], |
233
|
|
|
'empty filepath' => [ |
234
|
|
|
'', |
235
|
|
|
false, |
236
|
|
|
1, |
237
|
|
|
0, |
238
|
|
|
'text', |
239
|
|
|
], |
240
|
|
|
]; |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|