-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathUseAliasNameMatcherTest.php
More file actions
98 lines (81 loc) · 3.54 KB
/
UseAliasNameMatcherTest.php
File metadata and controls
98 lines (81 loc) · 3.54 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
namespace Rector\Tests\PhpAttribute;
use Iterator;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\UseItem;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\PhpAttribute\UseAliasNameMatcher;
use Rector\PhpAttribute\ValueObject\UseAliasMetadata;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Annotation\OpenApi\Annotation\NestedPastAnnotation;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Annotation\OpenApi\PastAnnotation;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\Attribute\NestedFutureAttribute;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\FutureAttribute;
final class UseAliasNameMatcherTest extends AbstractLazyTestCase
{
private UseAliasNameMatcher $useAliasNameMatcher;
protected function setUp(): void
{
parent::setUp();
$this->useAliasNameMatcher = $this->make(UseAliasNameMatcher::class);
}
#[DataProvider('provideData')]
public function test(
AnnotationToAttribute $annotationToAttribute,
string $useImportName,
string $useAlias,
string $shortAnnotationName,
// attribute
string $expectedAttributeUseImportName,
string $expectedShortAttributeName,
): void {
$useItem = new UseItem(new Name($useImportName), $useAlias);
$useItem->setAttribute(AttributeKey::ORIGINAL_NODE, $useItem);
$uses = [new Use_([$useItem])];
// uses
$useAliasMetadata = $this->useAliasNameMatcher->match($uses, $shortAnnotationName, $annotationToAttribute);
$this->assertInstanceOf(UseAliasMetadata::class, $useAliasMetadata);
// test new use import
$this->assertSame($expectedShortAttributeName, $useAliasMetadata->getShortAttributeName());
// test new short attribute name
$this->assertSame($expectedAttributeUseImportName, $useAliasMetadata->getUseImportName());
}
/**
* @return Iterator<array<int, (AnnotationToAttribute|string)>>
*/
public static function provideData(): Iterator
{
yield [
// configuration
new AnnotationToAttribute(PastAnnotation::class, FutureAttribute::class),
// use import
'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Annotation\OpenApi',
// use import alias
'OA',
// short attribute name
'@OA\PastAnnotation',
// expected attribute import
'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi',
// expected attribute short name
'OA\FutureAttribute',
];
yield [
// configuration
new AnnotationToAttribute(NestedPastAnnotation::class, NestedFutureAttribute::class),
// use import
'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Annotation\OpenApi\Annotation',
// use import alias
'OA',
// short attribute name
'@OA\NestedPastAnnotation',
// expected attribute import
'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\Attribute',
// expected attribute short name
'OA\NestedFutureAttribute',
];
}
}