44
55use  LogicException ;
66use  PhpParser \Comment \Doc ;
7+ use  PhpParser \Internal \TokenStream ;
78use  PhpParser \Node  as  PhpNode ;
89use  PhpParser \NodeTraverser  as  PhpParserNodeTraverser ;
910use  PhpParser \NodeVisitor \CloningVisitor  as  PhpParserCloningVisitor ;
1011use  PhpParser \NodeVisitorAbstract ;
1112use  PhpParser \ParserFactory ;
13+ use  PhpParser \PrettyPrinter \Standard ;
1214use  PHPStan \PhpDocParser \Ast \AbstractNodeVisitor ;
1315use  PHPStan \PhpDocParser \Ast \Node ;
1416use  PHPStan \PhpDocParser \Ast \NodeTraverser ;
2830
2931class  IntegrationPrinterWithPhpParserTest extends  TestCase
3032{
33+ 	private  const  TAB_WIDTH  = 4 ;
3134
3235	/** 
3336	 * @return iterable<array{string, string, NodeVisitor}> 
@@ -73,7 +76,6 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
7376		$ phpTraversernew  PhpParserNodeTraverser ();
7477		$ phpTraverseraddVisitor (new  PhpParserCloningVisitor ());
7578
76- 		$ printernew  PhpPrinter ();
7779		$ fileContentsfile_get_contents ($ file
7880		if  ($ fileContentsfalse ) {
7981			$ this fail ('Could not read  '  . $ file
@@ -85,6 +87,11 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
8587		}
8688		$ oldTokens$ phpParsergetTokens ();
8789
90+ 		$ phpTraverserIndentnew  PhpParserNodeTraverser ();
91+ 		$ indentDetectornew  PhpPrinterIndentationDetectorVisitor (new  TokenStream ($ oldTokensself ::TAB_WIDTH ));
92+ 		$ phpTraverserIndentaddVisitor ($ indentDetector
93+ 		$ phpTraverserIndenttraverse ($ oldStmts
94+ 
8895		$ phpTraverser2new  PhpParserNodeTraverser ();
8996		$ phpTraverser2addVisitor (new  class  ($ visitorextends  NodeVisitorAbstract {
9097
@@ -134,6 +141,7 @@ public function enterNode(PhpNode $phpNode)
134141		$ newStmts$ phpTraversertraverse ($ oldStmts
135142		$ newStmts$ phpTraverser2traverse ($ newStmts
136143
144+ 		$ printernew  Standard (['indent '  => str_repeat ($ indentDetectorindentCharacter , $ indentDetectorindentSize )]);
137145		$ newCode$ printerprintFormatPreserving ($ newStmts$ oldStmts$ oldTokens
138146		$ this assertStringEqualsFile ($ expectedFile$ newCode
139147	}
0 commit comments