77use PHPUnit \Framework \Attributes \RunTestsInSeparateProcesses ;
88use Rector \Configuration \Option ;
99use Rector \Configuration \Parameter \SimpleParameterProvider ;
10+ use Rector \Renaming \Rector \MethodCall \RenameMethodRector ;
11+ use Rector \Renaming \Rector \Name \RenameClassRector ;
12+ use Rector \Renaming \Rector \PropertyFetch \RenamePropertyRector ;
13+ use Rector \Renaming \ValueObject \MethodCallRename ;
14+ use Rector \Renaming \ValueObject \RenameProperty ;
1015use Rector \Symfony \Set \TwigSetList ;
1116use Rector \Testing \PHPUnit \AbstractLazyTestCase ;
1217use Rector \TypeDeclaration \Rector \ClassMethod \ReturnTypeFromReturnNewRector ;
@@ -29,4 +34,51 @@ public function test(): void
2934 // only collect root withRules()
3035 $ this ->assertCount (1 , SimpleParameterProvider ::provideArrayParameter (Option::ROOT_STANDALONE_REGISTERED_RULES ));
3136 }
37+
38+ public function testRuleWithConfigurationComposerVersionBoundOnSatisfiedConstraint (): void
39+ {
40+ $ rectorConfig = $ this ->getContainer ();
41+
42+ $ rectorConfig ->ruleWithConfigurationComposerVersionBound (
43+ RenameClassRector::class,
44+ [
45+ 'SomeOldClass ' => 'SomeNewClass ' ,
46+ ],
47+ 'phpunit/phpunit ' ,
48+ '>=9.0 '
49+ );
50+
51+ $ registeredRectorRules = SimpleParameterProvider ::provideArrayParameter (Option::REGISTERED_RECTOR_RULES );
52+ $ this ->assertContains (RenameClassRector::class, $ registeredRectorRules );
53+ }
54+
55+ public function testRuleWithConfigurationComposerVersionBoundOnUnsatisfiedConstraint (): void
56+ {
57+ $ rectorConfig = $ this ->getContainer ();
58+
59+ $ rectorConfig ->ruleWithConfigurationComposerVersionBound (
60+ RenameMethodRector::class,
61+ [new MethodCallRename ('SomeClass ' , 'oldMethod ' , 'newMethod ' )],
62+ 'phpunit/phpunit ' ,
63+ '<9.0 '
64+ );
65+
66+ $ registeredRectorRules = SimpleParameterProvider ::provideArrayParameter (Option::REGISTERED_RECTOR_RULES );
67+ $ this ->assertNotContains (RenameMethodRector::class, $ registeredRectorRules );
68+ }
69+
70+ public function testRuleWithConfigurationComposerVersionBoundOnMissingPackage (): void
71+ {
72+ $ rectorConfig = $ this ->getContainer ();
73+
74+ $ rectorConfig ->ruleWithConfigurationComposerVersionBound (
75+ RenamePropertyRector::class,
76+ [new RenameProperty ('SomeClass ' , 'oldProperty ' , 'newProperty ' )],
77+ 'not-installed/package ' ,
78+ '>=1.0 '
79+ );
80+
81+ $ registeredRectorRules = SimpleParameterProvider ::provideArrayParameter (Option::REGISTERED_RECTOR_RULES );
82+ $ this ->assertNotContains (RenamePropertyRector::class, $ registeredRectorRules );
83+ }
3284}
0 commit comments