Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions src/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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() !== []) {
Expand Down