Skip to content

Commit

Permalink
TypeParserTest - verify all nodes have attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 25, 2023
1 parent 6220c55 commit 142198e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<mixed>
*/
Expand Down

0 comments on commit 142198e

Please sign in to comment.