Repository navigation
Expand file tree
/
Copy pathOnlyRuleResolverTest.php
More file actions
114 lines (95 loc) · 4.01 KB
/
Copy pathOnlyRuleResolverTest.php
File metadata and controls
114 lines (95 loc) · 4.01 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
namespace Rector\Tests\Configuration;
use Rector\Configuration\OnlyRuleResolver;
use Rector\Contract\Rector\RectorInterface;
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\Exception\Configuration\RectorRuleNameAmbiguousException;
use Rector\Exception\Configuration\RectorRuleNotFoundException;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
final class OnlyRuleResolverTest extends AbstractLazyTestCase
{
private OnlyRuleResolver $onlyRuleResolver;
protected function setUp(): void
{
parent::setUp();
$this->bootFromConfigFiles([__DIR__ . '/config/only_rule_resolver_config.php']);
$rectorConfig = self::getContainer();
$this->onlyRuleResolver = new OnlyRuleResolver(iterator_to_array(
$rectorConfig->tagged(RectorInterface::class)
));
}
public function testResolveOk(): void
{
$this->assertSame(
RemoveDoubleAssignRector::class,
$this->onlyRuleResolver->resolve('Rector\\DeadCode\\Rector\\Assign\\RemoveDoubleAssignRector')
);
}
public function testResolveOkLeadingBackslash(): void
{
$this->assertSame(
RemoveDoubleAssignRector::class,
$this->onlyRuleResolver->resolve('\\Rector\\DeadCode\\Rector\\Assign\\RemoveDoubleAssignRector')
);
}
public function testResolveOkDoubleBackslashes(): void
{
$this->assertSame(
RemoveDoubleAssignRector::class,
$this->onlyRuleResolver->resolve('\\\\Rector\\\\DeadCode\\\\Rector\\\\Assign\\\\RemoveDoubleAssignRector'),
'We want to fix wrongly double-quoted backslashes automatically'
);
}
public function testResolveOkSingleQuotes(): void
{
$this->assertSame(
RemoveDoubleAssignRector::class,
$this->onlyRuleResolver->resolve("'Rector\\DeadCode\\Rector\\Assign\\RemoveDoubleAssignRector'"),
'Remove stray single quotes on Windows systems'
);
}
public function testResolveMissingBackslash(): void
{
$this->expectExceptionMessageIsOrContains(
'Rule "RectorDeadCodeRectorAssignRemoveDoubleAssignRector" was not found.' . PHP_EOL
. 'The rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only="My\\Rector\\Rule"'
);
$this->expectException(RectorRuleNotFoundException::class);
$this->onlyRuleResolver->resolve('RectorDeadCodeRectorAssignRemoveDoubleAssignRector');
}
public function testResolveNotFound(): void
{
$this->expectExceptionMessageIsOrContains(
'Rule "This\Rule\Does\Not\Exist" was not found.' . PHP_EOL
. 'Make sure it is registered in your config or in one of the sets'
);
$this->expectException(RectorRuleNotFoundException::class);
$this->onlyRuleResolver->resolve('This\\Rule\\Does\\Not\\Exist');
}
public function testResolveShortOk(): void
{
$this->assertSame(
RemoveUnusedPrivateMethodRector::class,
$this->onlyRuleResolver->resolve('RemoveUnusedPrivateMethodRector'),
);
}
public function testResolveShortOkTwoLevels(): void
{
$this->assertSame(
RemoveDoubleAssignRector::class,
$this->onlyRuleResolver->resolve('Assign\\RemoveDoubleAssignRector'),
);
}
public function testResolveShortAmbiguous(): void
{
$this->expectExceptionMessageIsOrContains(
'Short rule name "RemoveDoubleAssignRector" is ambiguous. Specify the full rule name:' . PHP_EOL
. '- Rector\\DeadCode\\Rector\\Assign\\RemoveDoubleAssignRector' . PHP_EOL
. '- Rector\\Tests\\Configuration\\Source\\RemoveDoubleAssignRector'
);
$this->expectException(RectorRuleNameAmbiguousException::class);
$this->onlyRuleResolver->resolve('RemoveDoubleAssignRector');
}
}