@@ -53,12 +53,17 @@ class PhpDocParserTest extends TestCase
53
53
/** @var PhpDocParser */
54
54
private $ phpDocParser ;
55
55
56
+ /** @var PhpDocParser */
57
+ private $ phpDocParserWithRequiredWhitespaceBeforeDescription ;
58
+
56
59
protected function setUp (): void
57
60
{
58
61
parent ::setUp ();
59
62
$ this ->lexer = new Lexer ();
60
63
$ constExprParser = new ConstExprParser ();
61
- $ this ->phpDocParser = new PhpDocParser (new TypeParser ($ constExprParser ), $ constExprParser );
64
+ $ typeParser = new TypeParser ($ constExprParser );
65
+ $ this ->phpDocParser = new PhpDocParser ($ typeParser , $ constExprParser );
66
+ $ this ->phpDocParserWithRequiredWhitespaceBeforeDescription = new PhpDocParser ($ typeParser , $ constExprParser , true );
62
67
}
63
68
64
69
@@ -83,14 +88,37 @@ protected function setUp(): void
83
88
* @dataProvider provideRealWorldExampleData
84
89
* @dataProvider provideDescriptionWithOrWithoutHtml
85
90
*/
86
- public function testParse (string $ label , string $ input , PhpDocNode $ expectedPhpDocNode , int $ nextTokenType = Lexer::TOKEN_END ): void
91
+ public function testParse (
92
+ string $ label ,
93
+ string $ input ,
94
+ PhpDocNode $ expectedPhpDocNode ,
95
+ ?PhpDocNode $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode = null
96
+ ): void
97
+ {
98
+ $ this ->executeTestParse (
99
+ $ this ->phpDocParser ,
100
+ $ label ,
101
+ $ input ,
102
+ $ expectedPhpDocNode
103
+ );
104
+
105
+ $ this ->executeTestParse (
106
+ $ this ->phpDocParserWithRequiredWhitespaceBeforeDescription ,
107
+ $ label ,
108
+ $ input ,
109
+ $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode ?? $ expectedPhpDocNode
110
+ );
111
+ }
112
+
113
+
114
+ private function executeTestParse (PhpDocParser $ phpDocParser , string $ label , string $ input , PhpDocNode $ expectedPhpDocNode ): void
87
115
{
88
116
$ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ input ));
89
- $ actualPhpDocNode = $ this -> phpDocParser ->parse ($ tokens );
117
+ $ actualPhpDocNode = $ phpDocParser ->parse ($ tokens );
90
118
91
119
$ this ->assertEquals ($ expectedPhpDocNode , $ actualPhpDocNode , $ label );
92
120
$ this ->assertSame ((string ) $ expectedPhpDocNode , (string ) $ actualPhpDocNode );
93
- $ this ->assertSame ($ nextTokenType , $ tokens ->currentTokenType ());
121
+ $ this ->assertSame (Lexer:: TOKEN_END , $ tokens ->currentTokenType ());
94
122
}
95
123
96
124
@@ -675,6 +703,16 @@ public function provideVarTagsData(): Iterator
675
703
)
676
704
),
677
705
]),
706
+ new PhpDocNode ([
707
+ new PhpDocTagNode (
708
+ '@var ' ,
709
+ new VarTagValueNode (
710
+ new IdentifierTypeNode ('Foo ' ),
711
+ '$foo ' ,
712
+ '#desc '
713
+ )
714
+ ),
715
+ ]),
678
716
];
679
717
680
718
yield [
@@ -1459,6 +1497,15 @@ public function provideReturnTagsData(): Iterator
1459
1497
yield [
1460
1498
'invalid variadic callable ' ,
1461
1499
'/** @return \Closure(...int, string): string */ ' ,
1500
+ new PhpDocNode ([
1501
+ new PhpDocTagNode (
1502
+ '@return ' ,
1503
+ new ReturnTagValueNode (
1504
+ new IdentifierTypeNode ('\Closure ' ),
1505
+ '(...int, string): string '
1506
+ )
1507
+ ),
1508
+ ]),
1462
1509
new PhpDocNode ([
1463
1510
new PhpDocTagNode (
1464
1511
'@return ' ,
@@ -2265,6 +2312,16 @@ public function provideSingleLinePhpDocData(): Iterator
2265
2312
yield [
2266
2313
'callable with incomplete signature without return type ' ,
2267
2314
'/** @var callable(int) */ ' ,
2315
+ new PhpDocNode ([
2316
+ new PhpDocTagNode (
2317
+ '@var ' ,
2318
+ new VarTagValueNode (
2319
+ new IdentifierTypeNode ('callable ' ),
2320
+ '' ,
2321
+ '(int) '
2322
+ )
2323
+ ),
2324
+ ]),
2268
2325
new PhpDocNode ([
2269
2326
new PhpDocTagNode (
2270
2327
'@var ' ,
@@ -4241,6 +4298,20 @@ public function provideDescriptionWithOrWithoutHtml(): Iterator
4241
4298
'/** ' . PHP_EOL .
4242
4299
' * @return Foo <strong>Important description ' . PHP_EOL .
4243
4300
' */ ' ,
4301
+ new PhpDocNode ([
4302
+ new PhpDocTagNode (
4303
+ '@return ' ,
4304
+ new ReturnTagValueNode (
4305
+ new GenericTypeNode (
4306
+ new IdentifierTypeNode ('Foo ' ),
4307
+ [
4308
+ new IdentifierTypeNode ('strong ' ),
4309
+ ]
4310
+ ),
4311
+ 'Important description '
4312
+ )
4313
+ ),
4314
+ ]),
4244
4315
new PhpDocNode ([
4245
4316
new PhpDocTagNode (
4246
4317
'@return ' ,
@@ -4305,14 +4376,20 @@ public function provideTagsWithNumbers(): Iterator
4305
4376
* @dataProvider dataParseTagValue
4306
4377
* @param PhpDocNode $expectedPhpDocNode
4307
4378
*/
4308
- public function testParseTagValue (string $ tag , string $ phpDoc , Node $ expectedPhpDocNode , int $ nextTokenType = Lexer::TOKEN_END ): void
4379
+ public function testParseTagValue (string $ tag , string $ phpDoc , Node $ expectedPhpDocNode ): void
4380
+ {
4381
+ $ this ->executeTestParseTagValue ($ this ->phpDocParser , $ tag , $ phpDoc , $ expectedPhpDocNode );
4382
+ $ this ->executeTestParseTagValue ($ this ->phpDocParserWithRequiredWhitespaceBeforeDescription , $ tag , $ phpDoc , $ expectedPhpDocNode );
4383
+ }
4384
+
4385
+ private function executeTestParseTagValue (PhpDocParser $ phpDocParser , string $ tag , string $ phpDoc , Node $ expectedPhpDocNode ): void
4309
4386
{
4310
4387
$ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ phpDoc ));
4311
- $ actualPhpDocNode = $ this -> phpDocParser ->parseTagValue ($ tokens , $ tag );
4388
+ $ actualPhpDocNode = $ phpDocParser ->parseTagValue ($ tokens , $ tag );
4312
4389
4313
4390
$ this ->assertEquals ($ expectedPhpDocNode , $ actualPhpDocNode );
4314
4391
$ this ->assertSame ((string ) $ expectedPhpDocNode , (string ) $ actualPhpDocNode );
4315
- $ this ->assertSame ($ nextTokenType , $ tokens ->currentTokenType ());
4392
+ $ this ->assertSame (Lexer:: TOKEN_END , $ tokens ->currentTokenType ());
4316
4393
}
4317
4394
4318
4395
}
0 commit comments