Skip to content

Commit

Permalink
PhpDocParserTest - 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 ffaba4f commit 69432fa
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\AssertTagMethodValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\AssertTagPropertyValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\AssertTagValueNode;
Expand Down Expand Up @@ -53,6 +54,7 @@
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPUnit\Framework\TestCase;
use function count;
use function sprintf;
use const PHP_EOL;

class PhpDocParserTest extends TestCase
Expand Down Expand Up @@ -5709,4 +5711,49 @@ public function testReturnTypeLinesAndIndexes(string $phpDoc, array $lines): voi
$this->assertSame($lines[3], $type->getAttribute(Attribute::END_INDEX));
}

/**
* @dataProvider provideTagsWithNumbers
* @dataProvider provideSpecializedTags
* @dataProvider provideParamTagsData
* @dataProvider provideTypelessParamTagsData
* @dataProvider provideVarTagsData
* @dataProvider provideReturnTagsData
* @dataProvider provideThrowsTagsData
* @dataProvider provideMixinTagsData
* @dataProvider provideDeprecatedTagsData
* @dataProvider providePropertyTagsData
* @dataProvider provideMethodTagsData
* @dataProvider provideSingleLinePhpDocData
* @dataProvider provideMultiLinePhpDocData
* @dataProvider provideTemplateTagsData
* @dataProvider provideExtendsTagsData
* @dataProvider provideTypeAliasTagsData
* @dataProvider provideTypeAliasImportTagsData
* @dataProvider provideAssertTagsData
* @dataProvider provideRealWorldExampleData
* @dataProvider provideDescriptionWithOrWithoutHtml
* @dataProvider provideTagsWithBackslash
* @dataProvider provideSelfOutTagsData
* @dataProvider provideParamOutTagsData
*/
public function testVerifyAttributes(string $label, string $input): void
{
$usedAttributes = ['lines' => true, 'indexes' => true];
$constExprParser = new ConstExprParser(true, true, $usedAttributes);
$typeParser = new TypeParser($constExprParser, true, $usedAttributes);
$phpDocParser = new PhpDocParser($typeParser, $constExprParser, true, true, $usedAttributes);
$tokens = new TokenIterator($this->lexer->tokenize($input));

$visitor = new NodeCollectingVisitor();
$traverser = new NodeTraverser([$visitor]);
$traverser->traverse([$phpDocParser->parse($tokens)]);

foreach ($visitor->nodes as $node) {
$this->assertNotNull($node->getAttribute(Attribute::START_LINE), sprintf('%s: %s', $label, $node));
$this->assertNotNull($node->getAttribute(Attribute::END_LINE), sprintf('%s: %s', $label, $node));
$this->assertNotNull($node->getAttribute(Attribute::START_INDEX), sprintf('%s: %s', $label, $node));
$this->assertNotNull($node->getAttribute(Attribute::END_INDEX), sprintf('%s: %s', $label, $node));
}
}

}

0 comments on commit 69432fa

Please sign in to comment.