44
55namespace Rector \Tests \Configuration ;
66
7+ use PHPStan \Reflection \ReflectionProvider ;
78use Rector \Configuration \OnlyRuleResolver ;
89use Rector \Contract \Rector \RectorInterface ;
910use Rector \DeadCode \Rector \Assign \RemoveDoubleAssignRector ;
1011use Rector \DeadCode \Rector \ClassMethod \RemoveUnusedPrivateMethodRector ;
1112use Rector \Exception \Configuration \RectorRuleNameAmbiguousException ;
1213use Rector \Exception \Configuration \RectorRuleNotFoundException ;
1314use Rector \Testing \PHPUnit \AbstractLazyTestCase ;
15+ use Rector \TypeDeclaration \Rector \StmtsAwareInterface \SafeDeclareStrictTypesRector ;
1416
1517final class OnlyRuleResolverTest extends AbstractLazyTestCase
1618{
@@ -23,9 +25,10 @@ protected function setUp(): void
2325 $ this ->bootFromConfigFiles ([__DIR__ . '/config/only_rule_resolver_config.php ' ]);
2426 $ rectorConfig = self ::getContainer ();
2527
26- $ this ->onlyRuleResolver = new OnlyRuleResolver (iterator_to_array (
27- $ rectorConfig ->tagged (RectorInterface::class)
28- ));
28+ $ this ->onlyRuleResolver = new OnlyRuleResolver (
29+ iterator_to_array ($ rectorConfig ->tagged (RectorInterface::class)),
30+ $ this ->make (ReflectionProvider::class)
31+ );
2932 }
3033
3134 public function testResolveOk (): void
@@ -109,6 +112,18 @@ public function testResolveShortOkTwoLevels(): void
109112 );
110113 }
111114
115+ public function testResolveExistingButNotRegistered (): void
116+ {
117+ $ this ->expectExceptionMessageIsOrContains (
118+ 'Rule "Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector" exists, but is not registered in your Rector config. '
119+ . PHP_EOL . 'Register it in your rector.php: ' . PHP_EOL . PHP_EOL
120+ . ' ->withRules([SafeDeclareStrictTypesRector::class]) '
121+ );
122+ $ this ->expectException (RectorRuleNotFoundException::class);
123+
124+ $ this ->onlyRuleResolver ->resolve (SafeDeclareStrictTypesRector::class);
125+ }
126+
112127 public function testResolveShortAmbiguous (): void
113128 {
114129 $ this ->expectExceptionMessageIsOrContains (
0 commit comments