|
9 | 9 | use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
|
10 | 10 | use PHPStan\PhpDocParser\Ast\ConstExpr\QuoteAwareConstExprStringNode;
|
11 | 11 | use PHPStan\PhpDocParser\Ast\Node;
|
| 12 | +use PHPStan\PhpDocParser\Ast\NodeTraverser; |
12 | 13 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
|
13 | 14 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
|
14 | 15 | use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
@@ -80,6 +81,34 @@ public function testParse(string $input, $expectedResult, int $nextTokenType = L
|
80 | 81 | }
|
81 | 82 |
|
82 | 83 |
|
| 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 | + |
83 | 112 | /**
|
84 | 113 | * @return array<mixed>
|
85 | 114 | */
|
|
0 commit comments