42
42
class PrinterTest extends TestCase
43
43
{
44
44
45
+ /** @var TypeParser */
46
+ private $ typeParser ;
47
+
45
48
/** @var PhpDocParser */
46
49
private $ phpDocParser ;
47
50
48
51
protected function setUp (): void
49
52
{
50
53
$ usedAttributes = ['lines ' => true , 'indexes ' => true ];
51
54
$ constExprParser = new ConstExprParser (true , true , $ usedAttributes );
55
+ $ this ->typeParser = new TypeParser ($ constExprParser , true , $ usedAttributes );
52
56
$ this ->phpDocParser = new PhpDocParser (
53
- new TypeParser ( $ constExprParser , true , $ usedAttributes ) ,
57
+ $ this -> typeParser ,
54
58
$ constExprParser ,
55
59
true ,
56
60
true ,
@@ -1190,7 +1194,7 @@ public function testPrintFormatPreserving(string $phpDoc, string $expectedResult
1190
1194
);
1191
1195
}
1192
1196
1193
- private function unsetAttributes (PhpDocNode $ node ): PhpDocNode
1197
+ private function unsetAttributes (Node $ node ): Node
1194
1198
{
1195
1199
$ visitor = new class extends AbstractNodeVisitor {
1196
1200
@@ -1213,4 +1217,61 @@ public function enterNode(Node $node)
1213
1217
return $ traverser ->traverse ([$ node ])[0 ];
1214
1218
}
1215
1219
1220
+ public function dataPrintType (): iterable
1221
+ {
1222
+ yield [
1223
+ new IdentifierTypeNode ('int ' ),
1224
+ 'int ' ,
1225
+ ];
1226
+ }
1227
+
1228
+ /**
1229
+ * @dataProvider dataPrintType
1230
+ */
1231
+ public function testPrintType (TypeNode $ node , string $ expectedResult ): void
1232
+ {
1233
+ $ printer = new Printer ();
1234
+ $ phpDoc = $ printer ->print ($ node );
1235
+ $ this ->assertSame ($ expectedResult , $ phpDoc );
1236
+
1237
+ $ lexer = new Lexer ();
1238
+ $ this ->assertEquals (
1239
+ $ this ->unsetAttributes ($ node ),
1240
+ $ this ->unsetAttributes ($ this ->typeParser ->parse (new TokenIterator ($ lexer ->tokenize ($ phpDoc ))))
1241
+ );
1242
+ }
1243
+
1244
+ public function dataPrintPhpDocNode (): iterable
1245
+ {
1246
+ yield [
1247
+ new PhpDocNode ([
1248
+ new PhpDocTagNode ('@param ' , new ParamTagValueNode (
1249
+ new IdentifierTypeNode ('int ' ),
1250
+ false ,
1251
+ '$a ' ,
1252
+ ''
1253
+ )),
1254
+ ]),
1255
+ '/**
1256
+ * @param int $a
1257
+ */ ' ,
1258
+ ];
1259
+ }
1260
+
1261
+ /**
1262
+ * @dataProvider dataPrintPhpDocNode
1263
+ */
1264
+ public function testPrintPhpDocNode (PhpDocNode $ node , string $ expectedResult ): void
1265
+ {
1266
+ $ printer = new Printer ();
1267
+ $ phpDoc = $ printer ->print ($ node );
1268
+ $ this ->assertSame ($ expectedResult , $ phpDoc );
1269
+
1270
+ $ lexer = new Lexer ();
1271
+ $ this ->assertEquals (
1272
+ $ this ->unsetAttributes ($ node ),
1273
+ $ this ->unsetAttributes ($ this ->phpDocParser ->parse (new TokenIterator ($ lexer ->tokenize ($ phpDoc ))))
1274
+ );
1275
+ }
1276
+
1216
1277
}
0 commit comments