diff --git a/composer.json b/composer.json index 7c67b85..3cd17f6 100644 --- a/composer.json +++ b/composer.json @@ -54,9 +54,11 @@ "phpstan/phpstan": "*", "phpstan/phpstan-symfony": "*", "phpunit/phpunit": "^10.5|^11|^12|^13", + "psr/log": "^2|^3", "rector/rector": "*", "roave/security-advisories": "dev-latest", "symfony/filesystem": "^6.4|^7.4|^8", + "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..f661c52 --- /dev/null +++ b/tests/App/TestKernel.php @@ -0,0 +1,98 @@ +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]]); + } + + // Tasks referenced by code (task: ): process-bundle 5.4 or later + if (class_exists(TaskRegistry::class)) { + $container->extension('clever_age_process', [ + 'configurations' => [ + 'test.archive' => [ + 'tasks' => [ + 'zip' => [ + 'task' => 'archive_zip', + 'options' => ['filename' => 'archive.zip', 'files' => [], 'files_base_path' => '/tmp'], + ], + 'unzip' => [ + 'task' => 'archive_unzip', + 'options' => ['filename' => 'archive.zip', 'destination' => '/tmp'], + ], + ], + ], + ], + ]); + $services = $container->services(); + $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().'/archive_process_bundle_tests_'.getmypid(); + } +} diff --git a/tests/Functional/KernelTest.php b/tests/Functional/KernelTest.php new file mode 100644 index 0000000..cdb38d4 --- /dev/null +++ b/tests/Functional/KernelTest.php @@ -0,0 +1,82 @@ +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 testTasksAreRegistered(): void + { + $container = self::getContainer(); + + self::assertTrue($container->has(ZipTask::class)); + self::assertTrue($container->has(UnzipTask::class)); + } + + 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.archive'); + self::assertInstanceOf(ZipTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('zip'))); + self::assertInstanceOf(UnzipTask::class, $taskRegistry->getTask($processConfiguration->getTaskConfiguration('unzip'))); + } + + 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..37b3899 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,19 @@ +