mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 02:36:52 +01:00
allow testing outside Rector
This commit is contained in:
parent
3b482e5138
commit
9f9b939052
@ -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() !== []) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user