-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathStaticDoctrineAnnotationParserTest.php
More file actions
63 lines (51 loc) · 2.09 KB
/
StaticDoctrineAnnotationParserTest.php
File metadata and controls
63 lines (51 loc) · 2.09 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
use Iterator;
use PhpParser\Node\Scalar\String_;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
final class StaticDoctrineAnnotationParserTest extends AbstractLazyTestCase
{
private StaticDoctrineAnnotationParser $staticDoctrineAnnotationParser;
private TokenIteratorFactory $tokenIteratorFactory;
protected function setUp(): void
{
parent::setUp();
$this->tokenIteratorFactory = $this->make(TokenIteratorFactory::class);
$this->staticDoctrineAnnotationParser = $this->make(StaticDoctrineAnnotationParser::class);
}
/**
* @param CurlyListNode|array<string, CurlyListNode> $expectedValue
*/
#[DataProvider('provideData')]
public function test(string $docContent, CurlyListNode | array $expectedValue): void
{
$betterTokenIterator = $this->tokenIteratorFactory->create($docContent);
$string = new String_('some_node');
$value = $this->staticDoctrineAnnotationParser->resolveAnnotationValue($betterTokenIterator, $string);
// "equals" on purpose to compare 2 object with same content
$this->assertEquals($expectedValue, $value);
}
/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
$curlyListNode = new CurlyListNode([
new ArrayItemNode(new StringNode('chalet')),
new ArrayItemNode(new StringNode('apartment')),
]);
yield ['{"chalet", "apartment"}', $curlyListNode];
yield [
'key={"chalet", "apartment"}', [
'key' => $curlyListNode,
],
];
}
}