Skip to content

Commit d789c95

Browse files
committed
Test Doctrine node attributes
1 parent 886f662 commit d789c95

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Diff for: tests/PHPStan/Parser/PhpDocParserTest.php

+61
Original file line numberDiff line numberDiff line change
@@ -5949,6 +5949,67 @@ public function testLinesAndIndexes(string $phpDoc, array $childrenLines): void
59495949
}
59505950
}
59515951

5952+
5953+
/**
5954+
* @return iterable<array{string, list<array{int, int, int, int}>}>
5955+
*/
5956+
public function dataDeepNodesLinesAndIndexes(): iterable
5957+
{
5958+
yield [
5959+
'/**' . PHP_EOL .
5960+
' * @X({' . PHP_EOL .
5961+
' * 1,' . PHP_EOL .
5962+
' * 2' . PHP_EOL .
5963+
' * , ' . PHP_EOL .
5964+
' * 3,' . PHP_EOL .
5965+
' * }' . PHP_EOL .
5966+
' * )' . PHP_EOL .
5967+
' */',
5968+
[
5969+
[1, 9, 0, 25], // PhpDocNode
5970+
[2, 8, 2, 23], // PhpDocTagNode
5971+
[2, 8, 3, 23], // DoctrineTagValueNode
5972+
[2, 8, 3, 23], // DoctrineAnnotation
5973+
[2, 8, 4, 22], // DoctrineArgument
5974+
[2, 8, 4, 22], // DoctrineArray
5975+
[3, 3, 7, 7], // DoctrineArrayItem
5976+
[3, 3, 7, 7], // ConstExprIntegerNode
5977+
[4, 5, 11, 12], // DoctrineArrayItem
5978+
[4, 5, 11, 12], // ConstExprIntegerNode
5979+
[6, 6, 18, 18], // DoctrineArrayItem
5980+
[6, 6, 18, 18], // ConstExprIntegerNode
5981+
],
5982+
];
5983+
}
5984+
5985+
5986+
/**
5987+
* @dataProvider dataDeepNodesLinesAndIndexes
5988+
* @param list<array{int, int, int, int}> $nodeAttributes
5989+
*/
5990+
public function testDeepNodesLinesAndIndexes(string $phpDoc, array $nodeAttributes): void
5991+
{
5992+
$tokens = new TokenIterator($this->lexer->tokenize($phpDoc));
5993+
$usedAttributes = [
5994+
'lines' => true,
5995+
'indexes' => true,
5996+
];
5997+
$constExprParser = new ConstExprParser(true, true, $usedAttributes);
5998+
$typeParser = new TypeParser($constExprParser, true, $usedAttributes);
5999+
$phpDocParser = new PhpDocParser($typeParser, $constExprParser, true, true, $usedAttributes, true);
6000+
$visitor = new NodeCollectingVisitor();
6001+
$traverser = new NodeTraverser([$visitor]);
6002+
$traverser->traverse([$phpDocParser->parse($tokens)]);
6003+
$nodes = $visitor->nodes;
6004+
$this->assertCount(count($nodeAttributes), $nodes);
6005+
foreach ($nodes as $i => $node) {
6006+
$this->assertSame($nodeAttributes[$i][0], $node->getAttribute(Attribute::START_LINE), sprintf('Start line of %d. node', $i + 1));
6007+
$this->assertSame($nodeAttributes[$i][1], $node->getAttribute(Attribute::END_LINE), sprintf('End line of %d. node', $i + 1));
6008+
$this->assertSame($nodeAttributes[$i][2], $node->getAttribute(Attribute::START_INDEX), sprintf('Start index of %d. node', $i + 1));
6009+
$this->assertSame($nodeAttributes[$i][3], $node->getAttribute(Attribute::END_INDEX), sprintf('End index of %d. node', $i + 1));
6010+
}
6011+
}
6012+
59526013
/**
59536014
* @return array<mixed>
59546015
*/

0 commit comments

Comments
 (0)