diff --git a/tests/PHPStan/Parser/TypeParserTest.php b/tests/PHPStan/Parser/TypeParserTest.php index bc16e658..9d94c6de 100644 --- a/tests/PHPStan/Parser/TypeParserTest.php +++ b/tests/PHPStan/Parser/TypeParserTest.php @@ -9,6 +9,7 @@ use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode; use PHPStan\PhpDocParser\Ast\ConstExpr\QuoteAwareConstExprStringNode; use PHPStan\PhpDocParser\Ast\Node; +use PHPStan\PhpDocParser\Ast\NodeTraverser; use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode; use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; @@ -80,6 +81,34 @@ public function testParse(string $input, $expectedResult, int $nextTokenType = L } + /** + * @dataProvider provideParseData + * @param TypeNode|Exception $expectedResult + */ + public function testVerifyAttributes(string $input, $expectedResult): void + { + if ($expectedResult instanceof Exception) { + $this->expectException(get_class($expectedResult)); + $this->expectExceptionMessage($expectedResult->getMessage()); + } + + $usedAttributes = ['lines' => true, 'indexes' => true]; + $typeParser = new TypeParser(new ConstExprParser(true, true, $usedAttributes), true, $usedAttributes); + $tokens = new TokenIterator($this->lexer->tokenize($input)); + + $visitor = new NodeCollectingVisitor(); + $traverser = new NodeTraverser([$visitor]); + $traverser->traverse([$typeParser->parse($tokens)]); + + foreach ($visitor->nodes as $node) { + $this->assertNotNull($node->getAttribute(Attribute::START_LINE), (string) $node); + $this->assertNotNull($node->getAttribute(Attribute::END_LINE), (string) $node); + $this->assertNotNull($node->getAttribute(Attribute::START_INDEX), (string) $node); + $this->assertNotNull($node->getAttribute(Attribute::END_INDEX), (string) $node); + } + } + + /** * @return array */