File: AttributesTest.php

package info (click to toggle)
php-phpstan-phpdoc-parser 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,476 kB
  • sloc: php: 21,156; makefile: 50; xml: 42; sh: 17
file content (47 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php declare(strict_types = 1);

namespace PHPStan\PhpDocParser\Ast\Attributes;

use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use PHPUnit\Framework\TestCase;

final class AttributesTest extends TestCase
{

	private PhpDocNode $phpDocNode;

	protected function setUp(): void
	{
		parent::setUp();

		$config = new ParserConfig([]);
		$lexer = new Lexer($config);
		$constExprParser = new ConstExprParser($config);
		$phpDocParser = new PhpDocParser($config, new TypeParser($config, $constExprParser), $constExprParser);

		$input = '/** @var string */';
		$tokens = new TokenIterator($lexer->tokenize($input));
		$this->phpDocNode = $phpDocParser->parse($tokens);
	}

	public function testGetAttribute(): void
	{
		$unKnownValue = $this->phpDocNode->getAttribute('unknown');
		$this->assertNull($unKnownValue);
	}

	public function testSetAttribute(): void
	{
		$this->phpDocNode->setAttribute('key', 'value');

		$attributeValue = $this->phpDocNode->getAttribute('key');
		$this->assertSame('value', $attributeValue);
	}

}