-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathAnnotationToAttributeMapperTest.php
More file actions
57 lines (48 loc) · 1.67 KB
/
AnnotationToAttributeMapperTest.php
File metadata and controls
57 lines (48 loc) · 1.67 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
<?php
declare(strict_types=1);
namespace Rector\Tests\PhpAttribute\AnnotationToAttributeMapper;
use Iterator;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\String_;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
final class AnnotationToAttributeMapperTest extends AbstractLazyTestCase
{
private AnnotationToAttributeMapper $annotationToAttributeMapper;
protected function setUp(): void
{
parent::setUp();
$this->annotationToAttributeMapper = $this->make(AnnotationToAttributeMapper::class);
}
/**
* @param class-string<Expr> $expectedTypeClass
*/
#[DataProvider('provideData')]
public function test(mixed $input, string $expectedTypeClass): void
{
$mappedExpr = $this->annotationToAttributeMapper->map($input);
$this->assertInstanceOf($expectedTypeClass, $mappedExpr);
if ($mappedExpr instanceof Array_) {
$arrayItem = $mappedExpr->items[0];
$this->assertInstanceOf(ArrayItem::class, $arrayItem);
$this->assertInstanceOf(String_::class, $arrayItem->value);
}
}
/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [false, ConstFetch::class];
yield ['false', String_::class];
yield ['100', String_::class];
yield ['hey', String_::class];
yield [['hey'], Array_::class];
yield [100, Int_::class];
}
}