-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathArrayParserTest.php
More file actions
58 lines (45 loc) · 1.85 KB
/
ArrayParserTest.php
File metadata and controls
58 lines (45 loc) · 1.85 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
<?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\ArrayParser;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
final class ArrayParserTest extends AbstractLazyTestCase
{
private ArrayParser $arrayParser;
private TokenIteratorFactory $tokenIteratorFactory;
protected function setUp(): void
{
parent::setUp();
$this->arrayParser = $this->make(ArrayParser::class);
$this->tokenIteratorFactory = $this->make(TokenIteratorFactory::class);
}
/**
* @param ArrayItemNode[] $expectedArrayItemNodes
*/
#[DataProvider('provideData')]
public function test(string $docContent, array $expectedArrayItemNodes): void
{
$betterTokenIterator = $this->tokenIteratorFactory->create($docContent);
$string = new String_('some_node');
$arrayItemNodes = $this->arrayParser->parseCurlyArray($betterTokenIterator, $string);
$this->assertEquals($expectedArrayItemNodes, $arrayItemNodes);
}
/**
* @return Iterator<array<int, (array<int, ArrayItemNode>|string)>>
*/
public static function provideData(): Iterator
{
yield ['{key: "value"}', [new ArrayItemNode(new StringNode('value'), 'key')]];
yield ['{"key": "value"}', [new ArrayItemNode(new StringNode('value'), new StringNode('key'))]];
yield ['{"value", "value2"}', [
new ArrayItemNode(new StringNode('value')),
new ArrayItemNode(new StringNode('value2')),
]];
}
}