44
55namespace DocBlock \Tags ;
66
7- use Mockery as m ;
7+ use InvalidArgumentException ;
88use phpDocumentor \Reflection \DocBlock \Tags \Example ;
99use PHPUnit \Framework \TestCase ;
1010
1111/**
1212 * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Example
13+ * @covers ::<private>
1314 */
1415class ExampleTest extends TestCase
1516{
1617 /**
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
2619 *
2720 * @covers ::create
2821 * @covers ::__construct
@@ -37,7 +30,7 @@ public function testExampleWithoutContent() : void
3730 }
3831
3932 /**
40- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
33+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
4134 *
4235 * @covers ::create
4336 * @covers ::__construct
@@ -52,7 +45,7 @@ public function testWithDescription() : void
5245 }
5346
5447 /**
55- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
48+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
5649 *
5750 * @covers ::create
5851 * @covers ::__construct
@@ -67,7 +60,7 @@ public function testStartlineIsParsed() : void
6760 }
6861
6962 /**
70- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
63+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
7164 *
7265 * @covers ::create
7366 * @covers ::__construct
@@ -84,7 +77,7 @@ public function testAllowOmitingLineCount() : void
8477 }
8578
8679 /**
87- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
80+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
8881 *
8982 * @covers ::create
9083 * @covers ::__construct
@@ -101,21 +94,149 @@ public function testLengthIsParsed() : void
10194 }
10295
10396 /**
104- * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
97+ * @uses \ phpDocumentor\Reflection\DocBlock\Tags\BaseTag
10598 *
99+ * @dataProvider tagContentProvider
106100 * @covers ::create
107101 * @covers ::__construct
108102 * @covers ::getFilePath
109103 * @covers ::getStartingLine
110104 * @covers ::getLineCount
111105 * @covers ::getDescription
106+ * @covers ::getContent
112107 */
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
114126 {
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+ ];
120241 }
121242}
0 commit comments