|
3 | 3 | namespace PHPStan\PhpDocParser\Printer;
|
4 | 4 |
|
5 | 5 | use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
|
| 6 | +use PHPStan\PhpDocParser\Ast\Attribute; |
6 | 7 | use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayItemNode;
|
7 | 8 | use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayNode;
|
8 | 9 | use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
|
@@ -1173,7 +1174,37 @@ public function testPrintFormatPreserving(string $phpDoc, string $expectedResult
|
1173 | 1174 | [$newNode] = $changingTraverser->traverse($newNodes);
|
1174 | 1175 |
|
1175 | 1176 | $printer = new Printer();
|
1176 |
| - $this->assertSame($expectedResult, $printer->printFormatPreserving($newNode, $phpDocNode, $tokens)); |
| 1177 | + $newPhpDoc = $printer->printFormatPreserving($newNode, $phpDocNode, $tokens); |
| 1178 | + $this->assertSame($expectedResult, $newPhpDoc); |
| 1179 | + |
| 1180 | + $newTokens = new TokenIterator($lexer->tokenize($newPhpDoc)); |
| 1181 | + $this->assertEquals( |
| 1182 | + $this->unsetAttributes($newNode), |
| 1183 | + $this->unsetAttributes($phpDocParser->parse($newTokens)) |
| 1184 | + ); |
| 1185 | + } |
| 1186 | + |
| 1187 | + private function unsetAttributes(PhpDocNode $node): PhpDocNode |
| 1188 | + { |
| 1189 | + $visitor = new class extends AbstractNodeVisitor { |
| 1190 | + |
| 1191 | + public function enterNode(Node $node) |
| 1192 | + { |
| 1193 | + $node->setAttribute(Attribute::START_LINE, null); |
| 1194 | + $node->setAttribute(Attribute::END_LINE, null); |
| 1195 | + $node->setAttribute(Attribute::START_INDEX, null); |
| 1196 | + $node->setAttribute(Attribute::END_INDEX, null); |
| 1197 | + $node->setAttribute(Attribute::ORIGINAL_NODE, null); |
| 1198 | + |
| 1199 | + return $node; |
| 1200 | + } |
| 1201 | + |
| 1202 | + }; |
| 1203 | + |
| 1204 | + $traverser = new NodeTraverser([$visitor]); |
| 1205 | + |
| 1206 | + /** @var PhpDocNode */ |
| 1207 | + return $traverser->traverse([$node])[0]; |
1177 | 1208 | }
|
1178 | 1209 |
|
1179 | 1210 | }
|
0 commit comments