Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cf694fd

Browse files
PrinterTest - parse the new printed node again and verify the AST is the same
1 parent 0b4de96 commit cf694fd

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

‎tests/PHPStan/Printer/PrinterTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\PhpDocParser\Printer;
44

55
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
6+
use PHPStan\PhpDocParser\Ast\Attribute;
67
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayItemNode;
78
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayNode;
89
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
@@ -1173,7 +1174,37 @@ public function testPrintFormatPreserving(string $phpDoc, string $expectedResult
11731174
[$newNode] = $changingTraverser->traverse($newNodes);
11741175

11751176
$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];
11771208
}
11781209

11791210
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /