Repository navigation
Expand file tree
/
Copy pathRectorConfigTest.php
More file actions
84 lines (69 loc) · 3.04 KB
/
Copy pathRectorConfigTest.php
File metadata and controls
84 lines (69 loc) · 3.04 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Config;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
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\TwigSetList;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector;
/**
* On macOS, this file order config cause this container read other tests' config.
* so, this #[RunTestsInSeparateProcesses] is needed.
*/
#[RunTestsInSeparateProcesses]
final class RectorConfigTest extends AbstractLazyTestCase
{
public function test(): void
{
$rectorConfig = $this->getContainer();
$rectorConfig->configure()
->withSets([TwigSetList::TWIG_134])
->withRules([ReturnTypeFromReturnNewRector::class])($rectorConfig);
// 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);
}
}