Remove YAML from tests (#3989)

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2020-08-19 18:00:27 +02:00 committed by GitHub
parent 86a3252d0d
commit 752a35253b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 104 additions and 32 deletions

View File

@ -16,6 +16,7 @@
"doctrine/annotations": "^1.10.4",
"doctrine/inflector": "^1.4|^2.0",
"jean85/pretty-package-versions": "^1.2",
"migrify/php-config-printer": "^0.3.30",
"nette/robot-loader": "^3.2",
"nette/utils": "^3.1",
"nikic/php-parser": "^4.9",
@ -31,9 +32,9 @@
"symfony/finder": "^4.4.8|^5.0.6",
"symfony/process": "^4.4.8|^5.0.6",
"symplify/auto-bind-parameter": "^8.2.9",
"symplify/easy-testing": "^8.2.9",
"symplify/autowire-array-parameter": "^8.2.9",
"symplify/console-color-diff": "^8.2.9",
"symplify/easy-testing": "^8.2.9",
"symplify/package-builder": "^8.2.9",
"symplify/set-config-resolver": "^8.2.9",
"symplify/smart-file-system": "^8.2.9",
@ -42,8 +43,8 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"johnkary/phpunit-speedtrap": "^3.2",
"migrify/config-transformer": "^0.3.25",
"migrify/easy-ci": "^0.3.25",
"migrify/config-transformer": "^0.3.30",
"migrify/easy-ci": "^0.3.30",
"nette/application": "^3.0",
"nette/forms": "^3.0",
"ocramius/package-versions": "^1.4|^1.5",

View File

@ -19,8 +19,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
ReturnArrayClassMethodToYieldRector::METHODS_BY_TYPE => [
TestCase::class => ['provideData', 'provideData*', 'dataProvider', 'dataProvider*'],
],
],
]);
]]);
$parameters = $containerConfigurator->parameters();

View File

@ -4,18 +4,9 @@ declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
// @todo make part of Rector CI
// add array-types
$services->set(AddArrayParamDocTypeRector::class);
$services->set(AddArrayReturnDocTypeRector::class);
$containerConfigurator->import(__DIR__ . '/rector-recipe.php', null, 'not_found');
$parameters = $containerConfigurator->parameters();

View File

@ -16,13 +16,13 @@ use Rector\Core\NonPhpFile\NonPhpFileProcessor;
use Rector\Core\Stubs\StubLoader;
use Rector\Core\Testing\Application\EnabledRectorsProvider;
use Rector\Core\Testing\Finder\RectorsFinder;
use Rector\Core\Testing\PhpConfigPrinter\PhpConfigPrinterFactory;
use Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Source\ContainerInterface;
use Rector\Set\SetProvider;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Yaml\Yaml;
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
@ -91,6 +91,7 @@ abstract class AbstractGenericRectorTestCase extends AbstractKernelTestCase
if (defined('RECTOR_REPOSITORY')) {
$this->createRectorRepositoryContainer();
} else {
// boot core config, where 3rd party services might be loaded
$rootRectorPhp = getcwd() . '/rector.php';
$configs = [];
@ -100,7 +101,6 @@ abstract class AbstractGenericRectorTestCase extends AbstractKernelTestCase
// 3rd party
$configs[] = $this->getConfigFor3rdPartyTest();
$this->bootKernelWithConfigs(RectorKernel::class, $configs);
}
@ -187,7 +187,7 @@ abstract class AbstractGenericRectorTestCase extends AbstractKernelTestCase
}
/**
* @return mixed[][]|null[]
* @return array<string, mixed[]|null>
*/
protected function getCurrentTestRectorClassesWithConfiguration(): array
{
@ -279,15 +279,12 @@ abstract class AbstractGenericRectorTestCase extends AbstractKernelTestCase
private function getConfigFor3rdPartyTest(): string
{
$currentTestRectorClassesWithConfiguration = $this->getCurrentTestRectorClassesWithConfiguration();
$yamlContent = Yaml::dump([
'services' => $currentTestRectorClassesWithConfiguration,
], Yaml::DUMP_OBJECT_AS_MAP);
$rectorClassesWithConfiguration = $this->getCurrentTestRectorClassesWithConfiguration();
$configFileTempPath = sprintf(sys_get_temp_dir() . '/rector_temp_tests/current_test.yaml');
$this->smartFileSystem->dumpFile($configFileTempPath, $yamlContent);
$filePath = sprintf(sys_get_temp_dir() . '/rector_temp_tests/current_test.php');
$this->createPhpConfigFileAndDumpToPath($rectorClassesWithConfiguration, $filePath);
return $configFileTempPath;
return $filePath;
}
private function configurePhpVersionFeatures(): void
@ -340,16 +337,21 @@ abstract class AbstractGenericRectorTestCase extends AbstractKernelTestCase
$listForConfig[$rectorClass] = null;
}
// @todo PHP dump
$yamlContent = Yaml::dump([
'services' => $listForConfig,
], Yaml::DUMP_OBJECT_AS_MAP);
$filePath = sprintf(sys_get_temp_dir() . '/rector_temp_tests/all_rectors.php');
$this->createPhpConfigFileAndDumpToPath($listForConfig, $filePath);
$configFileTempPath = sprintf(sys_get_temp_dir() . '/rector_temp_tests/all_rectors.yaml');
$this->bootKernelWithConfigs(RectorKernel::class, [$filePath]);
}
$smartFileSystem = new SmartFileSystem();
$smartFileSystem->dumpFile($configFileTempPath, $yamlContent);
/**
* @param array<string, mixed[]|null> $rectorClassesWithConfiguration
*/
private function createPhpConfigFileAndDumpToPath(array $rectorClassesWithConfiguration, string $filePath): void
{
$phpConfigPrinterFactory = new PhpConfigPrinterFactory();
$smartPhpConfigPrinter = $phpConfigPrinterFactory->create();
$this->bootKernelWithConfigs(RectorKernel::class, [$configFileTempPath]);
$fileContent = $smartPhpConfigPrinter->printConfiguredServices($rectorClassesWithConfiguration);
$this->smartFileSystem->dumpFile($filePath, $fileContent);
}
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Testing\PhpConfigPrinter;
use Migrify\PhpConfigPrinter\HttpKernel\PhpConfigPrinterKernel;
use Migrify\PhpConfigPrinter\Printer\SmartPhpConfigPrinter;
final class PhpConfigPrinterFactory
{
public function create(): SmartPhpConfigPrinter
{
$phpConfigPrinterKernel = new PhpConfigPrinterKernel('prod', true);
$phpConfigPrinterKernel->setConfigs([__DIR__ . '/config/php-config-printer-config.php']);
$phpConfigPrinterKernel->boot();
$container = $phpConfigPrinterKernel->getContainer();
return $container->get(SmartPhpConfigPrinter::class);
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Testing\PhpConfigPrinter;
use Migrify\PhpConfigPrinter\Contract\SymfonyVersionFeatureGuardInterface;
final class SymfonyVersionFeatureGuard implements SymfonyVersionFeatureGuardInterface
{
public function isAtLeastSymfonyVersion(float $symfonyVersion): bool
{
return true;
}
}

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Testing\PhpConfigPrinter;
use Migrify\PhpConfigPrinter\Contract\YamlFileContentProviderInterface;
final class YamlFileContentProvider implements YamlFileContentProviderInterface
{
public function setContent(string $yamlContent): void
{
}
public function getYamlContent(): string
{
return '';
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use Migrify\PhpConfigPrinter\Contract\SymfonyVersionFeatureGuardInterface;
use Migrify\PhpConfigPrinter\Contract\YamlFileContentProviderInterface;
use Rector\Core\Testing\PhpConfigPrinter\SymfonyVersionFeatureGuard;
use Rector\Core\Testing\PhpConfigPrinter\YamlFileContentProvider;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->autowire();
$services->set(SymfonyVersionFeatureGuard::class);
$services->alias(SymfonyVersionFeatureGuardInterface::class, SymfonyVersionFeatureGuard::class);
$services->set(YamlFileContentProvider::class);
$services->alias(YamlFileContentProviderInterface::class, YamlFileContentProvider::class);
};