Skip to content

Commit 142198e

Browse files
committed
TypeParserTest - verify all nodes have attributes
1 parent 6220c55 commit 142198e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎tests/PHPStan/Parser/TypeParserTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
1010
use PHPStan\PhpDocParser\Ast\ConstExpr\QuoteAwareConstExprStringNode;
1111
use PHPStan\PhpDocParser\Ast\Node;
12+
use PHPStan\PhpDocParser\Ast\NodeTraverser;
1213
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
1314
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
1415
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
@@ -80,6 +81,34 @@ public function testParse(string $input, $expectedResult, int $nextTokenType = L
8081
}
8182

8283

84+
/**
85+
* @dataProvider provideParseData
86+
* @param TypeNode|Exception $expectedResult
87+
*/
88+
public function testVerifyAttributes(string $input, $expectedResult): void
89+
{
90+
if ($expectedResult instanceof Exception) {
91+
$this->expectException(get_class($expectedResult));
92+
$this->expectExceptionMessage($expectedResult->getMessage());
93+
}
94+
95+
$usedAttributes = ['lines' => true, 'indexes' => true];
96+
$typeParser = new TypeParser(new ConstExprParser(true, true, $usedAttributes), true, $usedAttributes);
97+
$tokens = new TokenIterator($this->lexer->tokenize($input));
98+
99+
$visitor = new NodeCollectingVisitor();
100+
$traverser = new NodeTraverser([$visitor]);
101+
$traverser->traverse([$typeParser->parse($tokens)]);
102+
103+
foreach ($visitor->nodes as $node) {
104+
$this->assertNotNull($node->getAttribute(Attribute::START_LINE), (string) $node);
105+
$this->assertNotNull($node->getAttribute(Attribute::END_LINE), (string) $node);
106+
$this->assertNotNull($node->getAttribute(Attribute::START_INDEX), (string) $node);
107+
$this->assertNotNull($node->getAttribute(Attribute::END_INDEX), (string) $node);
108+
}
109+
}
110+
111+
83112
/**
84113
* @return array<mixed>
85114
*/

0 commit comments

Comments
 (0)