-
-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathRectorConfigTest.php
More file actions
92 lines (75 loc) · 3.44 KB
/
Copy pathRectorConfigTest.php
File metadata and controls
92 lines (75 loc) · 3.44 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Config;
use Rector\Config\RectorConfig;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector;
final class RectorConfigTest extends AbstractLazyTestCase
{
protected function setUp(): void
{
parent::setUp();
// these tests assert on root rule registration, which is decided by a
// static "first configure() in the process is root" flag; reset it and
// the registered-rule lists so the assertions hold whether this class
// runs alone or batched into one warm process by a parallel runner
RectorConfig::resetRecreated();
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, []);
SimpleParameterProvider::setParameter(Option::ROOT_STANDALONE_REGISTERED_RULES, []);
}
public function test(): void
{
$rectorConfig = $this->getContainer();
$rectorConfig->configure()
->withSets([SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION])
->withRules([ReturnTypeFromReturnNewRector::class]);
// only collect root withRules()
$this->assertCount(1, SimpleParameterProvider::provideArrayParameter(Option::ROOT_STANDALONE_REGISTERED_RULES));
}
public function testRuleWithConfigurationComposerVersionBoundOnSatisfiedConstraint(): void
{
$rectorConfig = $this->getContainer();
$rectorConfig->ruleWithConfigurationComposerVersionBound(
RenameClassRector::class,
[
'SomeOldClass' => 'SomeNewClass',
],
'phpunit/phpunit',
'>=9.0'
);
$registeredRectorRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
$this->assertContains(RenameClassRector::class, $registeredRectorRules);
}
public function testRuleWithConfigurationComposerVersionBoundOnUnsatisfiedConstraint(): void
{
$rectorConfig = $this->getContainer();
$rectorConfig->ruleWithConfigurationComposerVersionBound(
RenameMethodRector::class,
[new MethodCallRename('SomeClass', 'oldMethod', 'newMethod')],
'phpunit/phpunit',
'<9.0'
);
$registeredRectorRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
$this->assertNotContains(RenameMethodRector::class, $registeredRectorRules);
}
public function testRuleWithConfigurationComposerVersionBoundOnMissingPackage(): void
{
$rectorConfig = $this->getContainer();
$rectorConfig->ruleWithConfigurationComposerVersionBound(
RenamePropertyRector::class,
[new RenameProperty('SomeClass', 'oldProperty', 'newProperty')],
'not-installed/package',
'>=1.0'
);
$registeredRectorRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
$this->assertNotContains(RenamePropertyRector::class, $registeredRectorRules);
}
}