Merge pull request #1897 from rectorphp/test-able

allow testing outside Rector
This commit is contained in:
Tomáš Votruba 2019-08-25 13:56:25 +02:00 committed by GitHub
commit 7037749681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,27 +56,31 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
$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 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
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 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
$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() !== []) {