4
4
5
5
namespace DocBlock \Tags ;
6
6
7
- use Mockery as m ;
7
+ use InvalidArgumentException ;
8
8
use phpDocumentor \Reflection \DocBlock \Tags \Example ;
9
9
use PHPUnit \Framework \TestCase ;
10
10
11
11
/**
12
12
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Example
13
+ * @covers ::<private>
13
14
*/
14
15
class ExampleTest extends TestCase
15
16
{
16
17
/**
17
- * Call Mockery::close after each test.
18
- */
19
- public function tearDown () : void
20
- {
21
- m::close ();
22
- }
23
-
24
- /**
25
- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
18
+ * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
26
19
*
27
20
* @covers ::create
28
21
* @covers ::__construct
@@ -37,7 +30,7 @@ public function testExampleWithoutContent() : void
37
30
}
38
31
39
32
/**
40
- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
33
+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
41
34
*
42
35
* @covers ::create
43
36
* @covers ::__construct
@@ -52,7 +45,7 @@ public function testWithDescription() : void
52
45
}
53
46
54
47
/**
55
- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
48
+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
56
49
*
57
50
* @covers ::create
58
51
* @covers ::__construct
@@ -67,7 +60,7 @@ public function testStartlineIsParsed() : void
67
60
}
68
61
69
62
/**
70
- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
63
+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
71
64
*
72
65
* @covers ::create
73
66
* @covers ::__construct
@@ -84,7 +77,7 @@ public function testAllowOmitingLineCount() : void
84
77
}
85
78
86
79
/**
87
- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
80
+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
88
81
*
89
82
* @covers ::create
90
83
* @covers ::__construct
@@ -101,21 +94,149 @@ public function testLengthIsParsed() : void
101
94
}
102
95
103
96
/**
104
- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
97
+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
105
98
*
99
+ * @dataProvider tagContentProvider
106
100
* @covers ::create
107
101
* @covers ::__construct
108
102
* @covers ::getFilePath
109
103
* @covers ::getStartingLine
110
104
* @covers ::getLineCount
111
105
* @covers ::getDescription
106
+ * @covers ::getContent
112
107
*/
113
- public function testFullExample () : void
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
114
126
{
115
- $ tag = Example::create ('"example1.php" 10 5 test text ' );
116
- $ this ->assertEquals ('example1.php ' , $ tag ->getFilePath ());
117
- $ this ->assertEquals (10 , $ tag ->getStartingLine ());
118
- $ this ->assertEquals (5 , $ tag ->getLineCount ());
119
- $ this ->assertEquals ('test text ' , $ tag ->getDescription ());
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
+ ];
120
241
}
121
242
}
0 commit comments