4242class PrinterTest extends TestCase
4343{
4444
45+ /** @var TypeParser */
46+ private $ typeParser ;
47+
4548 /** @var PhpDocParser */
4649 private $ phpDocParser ;
4750
4851 protected function setUp (): void
4952 {
5053 $ usedAttributes = ['lines ' => true , 'indexes ' => true ];
5154 $ constExprParser = new ConstExprParser (true , true , $ usedAttributes );
55+ $ this ->typeParser = new TypeParser ($ constExprParser , true , $ usedAttributes );
5256 $ this ->phpDocParser = new PhpDocParser (
53- new TypeParser ( $ constExprParser , true , $ usedAttributes ) ,
57+ $ this -> typeParser ,
5458 $ constExprParser ,
5559 true ,
5660 true ,
@@ -1190,7 +1194,7 @@ public function testPrintFormatPreserving(string $phpDoc, string $expectedResult
11901194 );
11911195 }
11921196
1193- private function unsetAttributes (PhpDocNode $ node ): PhpDocNode
1197+ private function unsetAttributes (Node $ node ): Node
11941198 {
11951199 $ visitor = new class extends AbstractNodeVisitor {
11961200
@@ -1213,4 +1217,61 @@ public function enterNode(Node $node)
12131217 return $ traverser ->traverse ([$ node ])[0 ];
12141218 }
12151219
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+
12161277}
0 commit comments