diff --git a/src/Testing/PHPUnit/AbstractRectorTestCase.php b/src/Testing/PHPUnit/AbstractRectorTestCase.php index de8119c8b340..3d7eae49544c 100644 --- a/src/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/src/Testing/PHPUnit/AbstractRectorTestCase.php @@ -56,27 +56,31 @@ protected function setUp(): void $this->fixtureSplitter = new FixtureSplitter($this->getTempPath()); // defined in phpunit.xml - if (defined('RECTOR_REPOSITORY') && $this->provideConfig() === '') { - if (self::$allRectorContainer === null) { - $this->createContainerWithAllRectors(); - - self::$allRectorContainer = self::$container; - } else { - // load from cache - self::$container = self::$allRectorContainer; - } - - $enabledRectorsProvider = static::$container->get(EnabledRectorsProvider::class); - $enabledRectorsProvider->reset(); - $this->configureEnabledRectors($enabledRectorsProvider); - } elseif ($this->provideConfig() !== '') { + if ($this->provideConfig() !== '') { $this->ensureConfigFileExists(); $this->bootKernelWithConfigs(RectorKernel::class, [$this->provideConfig()]); $enabledRectorsProvider = static::$container->get(EnabledRectorsProvider::class); $enabledRectorsProvider->reset(); } else { - throw new ShouldNotHappenException(); + // repare contains with all rectors + // cache only rector tests - defined in phpunit.xml + if (defined('RECTOR_REPOSITORY')) { + if (self::$allRectorContainer === null) { + $this->createContainerWithAllRectors(); + + self::$allRectorContainer = self::$container; + } else { + // load from cache + self::$container = self::$allRectorContainer; + } + } else { + $this->bootKernelWithConfigs(RectorKernel::class, [$this->provideConfig()]); + } + + $enabledRectorsProvider = self::$container->get(EnabledRectorsProvider::class); + $enabledRectorsProvider->reset(); + $this->configureEnabledRectors($enabledRectorsProvider); } // disable any output @@ -183,9 +187,12 @@ private function ensureConfigFileExists(): void private function createContainerWithAllRectors(): void { - $allRectorClasses = (new RectorsFinder())->findCoreRectorClasses(); + $coreRectorClasses = (new RectorsFinder())->findCoreRectorClasses(); + $configFileTempPath = sprintf(sys_get_temp_dir() . '/rector_temp_tests/all_rectors.yaml'); + $allRectorClasses = array_merge($coreRectorClasses, $this->getCurrentTestRectorClasses()); + $listForConfig = []; foreach ($allRectorClasses as $rectorClass) { $listForConfig[$rectorClass] = null; @@ -201,6 +208,18 @@ private function createContainerWithAllRectors(): void $this->bootKernelWithConfigs(RectorKernel::class, [$configFile]); } + /** + * @return string[] + */ + private function getCurrentTestRectorClasses(): array + { + if ($this->getRectorsWithConfiguration() !== []) { + return array_keys($this->getRectorsWithConfiguration()); + } + + return [$this->getRectorClass()]; + } + private function configureEnabledRectors(EnabledRectorsProvider $enabledRectorsProvider): void { if ($this->getRectorsWithConfiguration() !== []) {