|
2 | 2 |
|
3 | 3 | namespace PHPStan\PhpDocParser\Ast\Attributes; |
4 | 4 |
|
| 5 | +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; |
5 | 6 | use PHPStan\PhpDocParser\Lexer\Lexer; |
6 | 7 | use PHPStan\PhpDocParser\Parser\ConstExprParser; |
7 | 8 | use PHPStan\PhpDocParser\Parser\PhpDocParser; |
| 9 | +use PHPStan\PhpDocParser\Parser\TokenIterator; |
8 | 10 | use PHPStan\PhpDocParser\Parser\TypeParser; |
9 | 11 | use PHPUnit\Framework\TestCase; |
10 | 12 |
|
11 | 13 | final class AttributesTest extends TestCase |
12 | 14 | { |
13 | 15 |
|
14 | | - /** |
15 | | - * @var Lexer |
16 | | - */ |
17 | | - private $lexer; |
18 | | - |
19 | | - /** |
20 | | - * @var PhpDocParser |
21 | | - */ |
22 | | - private $phpDocParser; |
| 16 | + /** @var PhpDocNode */ |
| 17 | + private $phpDocNode; |
23 | 18 |
|
24 | 19 | protected function setUp(): void |
25 | 20 | { |
26 | 21 | parent::setUp(); |
27 | | - $this->lexer = new Lexer(); |
| 22 | + $lexer = new Lexer(); |
28 | 23 | $constExprParser = new ConstExprParser(); |
29 | | - $this->phpDocParser = new PhpDocParser(new TypeParser($constExprParser), $constExprParser); |
| 24 | + $phpDocParser = new PhpDocParser(new TypeParser($constExprParser), $constExprParser); |
| 25 | + |
| 26 | + $input = '/** @var string */'; |
| 27 | + $tokens = new TokenIterator($lexer->tokenize($input)); |
| 28 | + $this->phpDocNode = $phpDocParser->parse($tokens); |
| 29 | + } |
| 30 | + |
| 31 | + public function testGetAttribute(): void |
| 32 | + { |
| 33 | + $defaultValue = $this->phpDocNode->getAttribute('unknown_with_default', 100); |
| 34 | + $this->assertSame(100, $defaultValue); |
| 35 | + |
| 36 | + $unKnownValue = $this->phpDocNode->getAttribute('unknown'); |
| 37 | + $this->assertNull($unKnownValue); |
| 38 | + } |
| 39 | + |
| 40 | + public function testSetAttribute(): void |
| 41 | + { |
| 42 | + $this->phpDocNode->setAttribute('key', 'value'); |
| 43 | + |
| 44 | + $attributeValue = $this->phpDocNode->getAttribute('key'); |
| 45 | + $this->assertSame('value', $attributeValue); |
30 | 46 | } |
31 | 47 |
|
32 | 48 | } |
0 commit comments