diff --git a/composer.json b/composer.json index e4ff89f..adde310 100644 --- a/composer.json +++ b/composer.json @@ -50,8 +50,10 @@ "phpstan/phpstan": "*", "phpstan/phpstan-symfony": "*", "phpunit/phpunit": "^10.5 || ^11 || ^12 || ^13", + "psr/log": "^2 || ^3", "rector/rector": "*", "roave/security-advisories": "dev-latest", + "symfony/framework-bundle": "^6.4 || ^7.4 || ^8", "symfony/test-pack": "^1.1" }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6bdb884..9e8b688 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,20 +1,22 @@ + failOnWarning="true" + failOnDeprecation="true" + displayDetailsOnTestsThatTriggerDeprecations="true"> tests - + src diff --git a/rector.php b/rector.php index 7406cc2..ed380b2 100644 --- a/rector.php +++ b/rector.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; use Rector\Symfony\Set\SymfonySetList; use Rector\ValueObject\PhpVersion; @@ -20,4 +21,8 @@ ->withSets([ SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, ]) + ->withSkip([ + // Conditions on the Symfony version: always true with the installed version only + RemoveAlwaysTrueIfConditionRector::class => [__DIR__.'/tests/App/TestKernel.php'], + ]) ; diff --git a/tests/App/TestKernel.php b/tests/App/TestKernel.php new file mode 100644 index 0000000..d7e4ef1 --- /dev/null +++ b/tests/App/TestKernel.php @@ -0,0 +1,113 @@ +getRunDir().'/cache/'.$this->environment; + } + + public function getLogDir(): string + { + return $this->getRunDir().'/logs'; + } + + protected function configureContainer(ContainerConfigurator $container): void + { + $container->extension('framework', [ + 'secret' => 'test', + 'test' => true, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'validation' => ['email_validation_mode' => 'html5'], + ]); + if (Kernel::VERSION_ID >= 70300) { + // Not setting it is deprecated since Symfony 7.3: its default value changes in 8.0 + $container->extension('framework', ['property_info' => ['with_constructor_extractor' => true]]); + } + + $services = $container->services(); + $services->set('app.cache_adapter', Adapter::class) + ->args([inline_service(ArrayAdapter::class), 'app_tagged']) + ->tag('cleverage.cache.adapter', ['code' => 'app_tagged']); + $services->set(AttributedAdapter::class) + ->autoconfigure() + ->args([inline_service(ArrayAdapter::class), 'app_attributed']); + // Exposed to the tests + $services->alias('test.adapter_registry', AdapterRegistry::class)->public(); + + // Tasks referenced by code (task: ): process-bundle 5.4 or later + if (class_exists(TaskRegistry::class)) { + $container->extension('clever_age_process', [ + 'configurations' => [ + 'test.cache' => [ + 'tasks' => [ + 'get' => [ + 'task' => 'cache_get', + 'options' => ['adapter' => 'app_tagged', 'key' => 'key'], + ], + 'set' => [ + 'task' => 'cache_set', + 'options' => ['adapter' => 'app_tagged', 'key' => 'key'], + ], + ], + ], + ], + ]); + $services->alias('test.task_registry', TaskRegistry::class)->public(); + $services->alias('test.process_configuration_registry', ProcessConfigurationRegistry::class)->public(); + } + } + + private function getRunDir(): string + { + return sys_get_temp_dir().'/cache_process_bundle_tests_'.getmypid(); + } +} diff --git a/tests/Functional/KernelTest.php b/tests/Functional/KernelTest.php new file mode 100644 index 0000000..1e9e5cd --- /dev/null +++ b/tests/Functional/KernelTest.php @@ -0,0 +1,86 @@ +exceptionHandler = $this->getExceptionHandler(); + } + + protected function tearDown(): void + { + parent::tearDown(); + // The ErrorHandler registered when the kernel boots is not removed by the first Symfony 6.4 versions + if ($this->getExceptionHandler() !== $this->exceptionHandler) { + restore_exception_handler(); + } + } + + public function testAdaptersAreResolvedByCode(): void + { + $registry = self::getContainer()->get('test.adapter_registry'); + self::assertInstanceOf(AdapterRegistry::class, $registry); + + self::assertInstanceOf(Adapter::class, $registry->getAdapter('app_tagged')); + self::assertInstanceOf(AttributedAdapter::class, $registry->getAdapter('app_attributed')); + } + + public function testTasksAreResolvedByCode(): void + { + if (!class_exists(TaskRegistry::class)) { + self::markTestSkipped('The tasks are referenced by code since cleverage/process-bundle 5.4.'); + } + $processConfigurationRegistry = self::getContainer()->get('test.process_configuration_registry'); + self::assertInstanceOf(ProcessConfigurationRegistry::class, $processConfigurationRegistry); + $taskRegistry = self::getContainer()->get('test.task_registry'); + self::assertInstanceOf(TaskRegistry::class, $taskRegistry); + + $processConfiguration = $processConfigurationRegistry->getProcessConfiguration('test.cache'); + self::assertInstanceOf(GetTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('get'))); + self::assertInstanceOf(SetTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('set'))); + } + + private function getExceptionHandler(): mixed + { + $handler = set_exception_handler(null); + restore_exception_handler(); + + return $handler; + } + + protected static function getKernelClass(): string + { + return TestKernel::class; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..c91adef --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,19 @@ +