Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
verify indexes
  • Loading branch information
ondrejmirtes committed Feb 19, 2025
commit ac871aff25734a12b24ef5c59e35c49cf3b779c8
27 changes: 27 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,40 @@ public function testVerifyAttributes(string $input, $expectedResult): void
$this->assertNotNull($node->getAttribute(Attribute::END_INDEX), (string) $node);
}

$this->verifyNodeIndexes($node);

$this->assertEquals(
$this->unsetAllAttributesButComments($expectedResult),
$this->unsetAllAttributesButComments($typeNode),
);
}


private function verifyNodeIndexes(Node $node): void
{
$subNodeNames = array_keys(get_object_vars($node));
foreach ($subNodeNames as $subNodeName) {
$subNode = $node->$subNodeName;
if (is_array($subNode)) {
$lastEndIndex = null;
foreach ($subNode as $subSubNode) {
$startIndex = $subSubNode->getAttribute(Attribute::START_INDEX);
$endIndex = $subSubNode->getAttribute(Attribute::END_INDEX);
if ($lastEndIndex !== null) {
$this->assertGreaterThan($startIndex, $lastEndIndex, (string) $subSubNode);
}

$lastEndIndex = $endIndex;

$this->verifyNodeIndexes($subSubNode);
}
} elseif ($subNode instanceof Node) {
$this->verifyNodeIndexes($subNode);
}
}
}


private function unsetAllAttributes(Node $node): Node
{
$visitor = new class extends AbstractNodeVisitor {
Expand Down