diff --git a/CHANGELOG.md b/CHANGELOG.md index 55c7c20e..29ff2d87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Latest * [#280](https://github.com/cleverage/process-bundle/issues/280) The `code` attribute of the `cleverage.transformer` tag (or `#[AsTransformer]`) is required: a tagged service without code fails the container compilation. `TransformerInterface::getCode()` (and the `getCode()` method of the transformers of the bundle, except `GenericTransformer` and `UnavailableTransformer`), `TransformerRegistry::addTransformer()` and `RegistryCompilerPass`, deprecated since 5.4, are removed; the service locator is a required argument of the `TransformerRegistry` constructor; `TransformerRegistryInterface::getTransformerCodes()` gives the codes without instantiating the transformers (see `UPGRADE.md`). Update documentation, add tests. * [#292](https://github.com/cleverage/process-bundle/issues/292) Remove the fallbacks of the task registry on the service container, deprecated since 5.4 (#275): the `$container` argument of the `ProcessManager` constructor is removed and its `TaskRegistryInterface $taskRegistry` argument is required, before `$stopCheckers`; `ProcessHelpCommand` only accepts a `TaskRegistryInterface`; `TaskRegistry` only fetches the tasks from its service locator (a task of a process configuration unknown when the container is compiled is not found). The `service` key of the task configurations is removed, use `task: `. The tasks and transformers of the bundle, and the tasks of the application autoconfigured with `TaskInterface`, are private; `PublicTaskDeprecationCompilerPass` is removed (see `UPGRADE.md`). Update documentation and tests. * [#292](https://github.com/cleverage/process-bundle/issues/292) Reject the process configuration errors deprecated during v5: the `errors` task configuration key is removed (use `error_outputs`), with `TaskConfiguration::getErrors()` and `$logErrors`; an unknown `error_strategy` (#310) and an unknown task reference (#426) fail the container compilation; a task listed several times in the `outputs` / `error_outputs` of a task throws an `InvalidProcessConfigurationException` (#414); a shared service used by several tasks of a process fails the container compilation (#382). The former names of the codes with a dash, with underscores, are no longer found (#412, #475): processes, tasks, generic transformers, transformer codes and contextual options of the generic transformers; `DeprecatedCodeAliases` and the second argument of the `TransformerRegistry` constructor are removed (see `UPGRADE.md`). Update documentation and tests. +* [#292](https://github.com/cleverage/process-bundle/issues/292) Remove the classes, methods and options deprecated during v5: `ProcessState::getReturnCode()` / `setReturnCode()` (#503), the `cleverage_process.event_listener.data_queue` service and `DataQueueEventListener` (#311), `CheckSerializerCompilerPass`, the `KernelInterface` argument and the `$kernel` / `$logDir` properties of `CommandRunnerTask`, `ProcessLauncherTask` and `SubprocessInstance` (#318), the `process_options` option of the `process_launcher` task (see `UPGRADE.md`). Update documentation and tests. ## Changes * [#428](https://github.com/cleverage/process-bundle/issues/428) Tests on PHPUnit 12.5 and 13 (PHPUnit 10 and 11 dropped), with the lowest dependencies on PHP 8.3 and 8.5. diff --git a/UPGRADE.md b/UPGRADE.md index 6b855d14..d5c4b798 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -164,6 +164,21 @@ The former names of the codes with a dash, with underscores instead of dashes, a - the second argument of the `TransformerRegistry` constructor (former names, internal) and the internal `DeprecatedCodeAliases` class are removed. +### Removed classes, methods and options + +- `ProcessState::getReturnCode()` / `setReturnCode()` and the `$returnCode` property are removed (deprecated since + 5.10, used nowhere: the exit code of the command does not depend on them); +- the `cleverage_process.event_listener.data_queue` service and `DataQueueEventListener` are removed (deprecated since + 5.4, they kept a copy of the state of every `cleverage_process.data_queue` event in memory): write your own listener + of the event dispatched by the `event_dispatcher` task (see its reference page); +- `CheckSerializerCompilerPass` is removed (deprecated since 5.4, no longer registered by the bundle); +- `CommandRunnerTask`, `ProcessLauncherTask` and `SubprocessInstance` only accept the paths as strings (deprecated + since 5.4): the project directory for `CommandRunnerTask`, the path of the console (and the environment) for + `ProcessLauncherTask` and `SubprocessInstance`, no longer a `KernelInterface`. The deprecated `$kernel` property of + `CommandRunnerTask` and `ProcessLauncherTask`, and `SubprocessInstance::$logDir`, are removed. Only the definitions or subclasses of your application are concerned; +- the `process_options` option of the `process_launcher` task is removed (deprecated, a non-empty value already threw): + remove it from your process configurations, an `UndefinedOptionsException` is thrown otherwise. + ## v5.10 ### Stop strategy and error branch ending on a stop diff --git a/config/services/event.php b/config/services/event.php index 8025285e..17599316 100644 --- a/config/services/event.php +++ b/config/services/event.php @@ -13,17 +13,11 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; -use CleverAge\ProcessBundle\EventListener\DataQueueEventListener; use CleverAge\ProcessBundle\EventListener\SignalStopChecker; return static function (ContainerConfigurator $container): void { $services = $container->services(); - // @phpstan-ignore classConstant.deprecatedClass (deprecated service, removed in v6.0) - $services->set('cleverage_process.event_listener.data_queue', DataQueueEventListener::class) - ->deprecate('cleverage/process-bundle', '5.4', 'The "%service_id%" service is deprecated, it will be removed in v6.0: write your own listener of the event dispatched by the event_dispatcher task.') - ->tag('kernel.event_listener', ['event' => 'cleverage_process.data_queue', 'method' => 'pushData']); - $services->set('cleverage_process.event_listener.signal_stop_checker', SignalStopChecker::class) ->args([ service('logger')->ignoreOnInvalid(), diff --git a/docs/reference/tasks/event_dispatcher_task.md b/docs/reference/tasks/event_dispatcher_task.md index a85a2a6a..5977ade9 100644 --- a/docs/reference/tasks/event_dispatcher_task.md +++ b/docs/reference/tasks/event_dispatcher_task.md @@ -67,11 +67,6 @@ public function onDataQueue(EventDispatcherTaskEvent $event): void `CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent`. Every `EventDispatcherTask` without `event_name` then triggers the same listeners. -**Deprecated since 5.4, removed in v6.0**: the bundle listens to the `cleverage_process.data_queue` event with the -`cleverage_process.event_listener.data_queue` service (`DataQueueEventListener`), which keeps a copy of the -`ProcessState` of every event in memory. Injecting or fetching this service triggers an `E_USER_DEPRECATED` error: write -your own listener, as above. - **Deprecated since 5.1 (deprecation notice), removed in v6.0**: from v4.0 to v5.0, the `event_name` option was ignored and the event was always dispatched under its class name. To preserve backward compatibility, when `event_name` is set (and differs from the event class name) and listeners subscribe to `CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent`, the event is also diff --git a/docs/reference/tasks/process_launcher_task.md b/docs/reference/tasks/process_launcher_task.md index 13760d73..dff902ee 100644 --- a/docs/reference/tasks/process_launcher_task.md +++ b/docs/reference/tasks/process_launcher_task.md @@ -54,7 +54,6 @@ Options | `sleep_on_finalize_interval` | `int\|float` | | `1` | Time (in seconds) to wait at the end of **each** execution (each input) when no sub-process result is ready to be output, in addition to `sleep_interval_after_launch`: lower it to launch the sub-processes faster | | `context` | `array` | | `[]` | Context values passed to each sub-process (as `--context=key:value`, values must be scalars) | | `json_buffering` | `bool` | | `false` | Store each sub-process output in a JSON stream file and output its path | -| `process_options` | `array` | | `[]` | **Deprecated**: any non-empty value throws an `InvalidArgumentException` | Examples -------- diff --git a/src/DependencyInjection/Compiler/CheckSerializerCompilerPass.php b/src/DependencyInjection/Compiler/CheckSerializerCompilerPass.php deleted file mode 100644 index e2baaf47..00000000 --- a/src/DependencyInjection/Compiler/CheckSerializerCompilerPass.php +++ /dev/null @@ -1,42 +0,0 @@ -has('serializer') && !$container->has(DenormalizerInterface::class)) { - throw new AutowiringFailedException('serializer', self::MSG); - } - } -} diff --git a/src/EventListener/DataQueueEventListener.php b/src/EventListener/DataQueueEventListener.php deleted file mode 100644 index 9c54d756..00000000 --- a/src/EventListener/DataQueueEventListener.php +++ /dev/null @@ -1,53 +0,0 @@ -> - */ - protected array $queues = []; - - public function pushData(EventDispatcherTaskEvent $event): void - { - $queue = $this->getQueue($event->getState()->getProcessConfiguration()->getCode()); - $queue->push(clone $event->getState()); - } - - /** - * @return \SplQueue - */ - public function getQueue(string $processName): \SplQueue - { - if (!\array_key_exists($processName, $this->queues)) { - $this->queues[$processName] = new \SplQueue(); - } - - return $this->queues[$processName]; - } -} diff --git a/src/Model/ProcessState.php b/src/Model/ProcessState.php index 90af81bb..24e0262e 100644 --- a/src/Model/ProcessState.php +++ b/src/Model/ProcessState.php @@ -60,11 +60,6 @@ class ProcessState */ protected array $errorContext = []; - /** - * @deprecated since 5.10, used nowhere, will be removed in v6.0 - */ - protected ?int $returnCode = null; - protected bool $skipped; /** @@ -238,26 +233,6 @@ public function removeErrorContext(string|int $key): void unset($this->errorContext[$key]); } - /** - * @deprecated since 5.10, used nowhere, will be removed in v6.0 - */ - public function getReturnCode(): int - { - trigger_deprecation('cleverage/process-bundle', '5.10', 'The "%s()" method is deprecated: it is used nowhere and will be removed in 6.0.', __METHOD__); - - return $this->returnCode ?? 0; - } - - /** - * @deprecated since 5.10, used nowhere (the exit code of the command does not depend on it), will be removed in v6.0 - */ - public function setReturnCode(int $returnCode): void - { - trigger_deprecation('cleverage/process-bundle', '5.10', 'The "%s()" method is deprecated: it is used nowhere (the exit code of the command does not depend on it) and will be removed in 6.0.', __METHOD__); - - $this->returnCode = $returnCode; - } - public function isSkipped(): bool { return $this->skipped; diff --git a/src/Model/SubprocessInstance.php b/src/Model/SubprocessInstance.php index 0fa552b9..6d94bd52 100644 --- a/src/Model/SubprocessInstance.php +++ b/src/Model/SubprocessInstance.php @@ -16,7 +16,6 @@ use CleverAge\ProcessBundle\Exception\RuntimeException; use CleverAge\ProcessBundle\Filesystem\TemporaryFile; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; @@ -40,22 +39,15 @@ class SubprocessInstance */ protected array $options; - protected string $consolePath; - - /** - * @deprecated since 5.4, not used; only set when the kernel is passed to the constructor - */ - protected ?string $logDir = null; - /** - * @param string|KernelInterface $consolePath path of the Symfony console; passing the kernel is deprecated since 5.4 - * @param array $context - * @param array $options - * @param string|null $environment environment of the sub-process (--env), the default one of the console - * if null; taken from the kernel when it is passed + * @param string $consolePath path of the Symfony console + * @param array $context + * @param array $options + * @param string|null $environment environment of the sub-process (--env), the default one of the console if + * null */ public function __construct( - KernelInterface|string $consolePath, + protected string $consolePath, protected string $processCode, protected ?string $input, protected array $context = [], @@ -65,21 +57,6 @@ public function __construct( $resolver = new OptionsResolver(); $this->configureOptions($resolver); $this->options = $resolver->resolve($options); - - if ($consolePath instanceof KernelInterface) { - trigger_deprecation( - 'cleverage/process-bundle', - '5.4', - 'Passing a "%s" to "%s::__construct()" is deprecated, pass the path of the console and the environment instead. The argument will only accept a string in v6.0.', - KernelInterface::class, - self::class, - ); - $this->environment ??= $consolePath->getEnvironment(); - // @phpstan-ignore property.deprecated (kept for BC until v6.0) - $this->logDir = $consolePath->getLogDir().'/process'; - $consolePath = $consolePath->getProjectDir().'/bin/console'; - } - $this->consolePath = $consolePath; } /** diff --git a/src/Task/Process/CommandRunnerTask.php b/src/Task/Process/CommandRunnerTask.php index 0b87d84e..185b0c3b 100644 --- a/src/Task/Process/CommandRunnerTask.php +++ b/src/Task/Process/CommandRunnerTask.php @@ -15,7 +15,6 @@ use CleverAge\ProcessBundle\Model\AbstractConfigurableTask; use CleverAge\ProcessBundle\Model\ProcessState; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Process\Process; @@ -27,31 +26,11 @@ class CommandRunnerTask extends AbstractConfigurableTask { /** - * @deprecated since 5.4, only set when the kernel is passed to the constructor + * @param string $projectDir default working directory of the commands */ - protected ?KernelInterface $kernel = null; - - protected string $projectDir; - - /** - * @param string|KernelInterface $projectDir default working directory of the commands; passing the kernel is - * deprecated since 5.4 - */ - public function __construct(KernelInterface|string $projectDir) - { - if ($projectDir instanceof KernelInterface) { - trigger_deprecation( - 'cleverage/process-bundle', - '5.4', - 'Passing a "%s" to "%s::__construct()" is deprecated, pass the project directory instead. The argument will only accept a string in v6.0.', - KernelInterface::class, - self::class, - ); - // @phpstan-ignore property.deprecated (kept for BC until v6.0) - $this->kernel = $projectDir; - $projectDir = $projectDir->getProjectDir(); - } - $this->projectDir = $projectDir; + public function __construct( + protected string $projectDir, + ) { } public function execute(ProcessState $state): void diff --git a/src/Task/Process/ProcessLauncherTask.php b/src/Task/Process/ProcessLauncherTask.php index 728e7870..d3fea153 100644 --- a/src/Task/Process/ProcessLauncherTask.php +++ b/src/Task/Process/ProcessLauncherTask.php @@ -13,7 +13,6 @@ namespace CleverAge\ProcessBundle\Task\Process; -use CleverAge\ProcessBundle\Exception\InvalidArgumentException; use CleverAge\ProcessBundle\Exception\RuntimeException; use CleverAge\ProcessBundle\Model\AbstractConfigurableTask; use CleverAge\ProcessBundle\Model\FinalizableTaskInterface; @@ -25,7 +24,6 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -55,39 +53,16 @@ class ProcessLauncherTask extends AbstractConfigurableTask implements FlushableT protected bool $flushMode = false; /** - * @deprecated since 5.4, only set when the kernel is passed to the constructor - */ - protected ?KernelInterface $kernel = null; - - protected string $consolePath; - - /** - * @param string|KernelInterface $consolePath path of the Symfony console running the sub-processes; passing the - * kernel is deprecated since 5.4 - * @param string|null $environment environment of the sub-processes (--env), the default one of the - * console if null; taken from the kernel when it is passed + * @param string $consolePath path of the Symfony console running the sub-processes + * @param string|null $environment environment of the sub-processes (--env), the default one of the console if null */ public function __construct( protected LoggerInterface $logger, protected ProcessConfigurationRegistry $processRegistry, - KernelInterface|string $consolePath, + protected string $consolePath, protected ?string $environment = null, ) { $this->finishedBuffers = new \SplQueue(); - if ($consolePath instanceof KernelInterface) { - trigger_deprecation( - 'cleverage/process-bundle', - '5.4', - 'Passing a "%s" to "%s::__construct()" is deprecated, pass the path of the console and the environment instead. The argument will only accept a string in v6.0.', - KernelInterface::class, - self::class, - ); - // @phpstan-ignore property.deprecated (kept for BC until v6.0) - $this->kernel = $consolePath; - $this->environment ??= $consolePath->getEnvironment(); - $consolePath = $consolePath->getProjectDir().'/bin/console'; - } - $this->consolePath = $consolePath; } public function execute(ProcessState $state): void @@ -280,7 +255,6 @@ function (Options $options, $value) { 'sleep_interval' => 1, 'sleep_interval_after_launch' => 1, 'sleep_on_finalize_interval' => 1, - 'process_options' => [], 'context' => [], 'json_buffering' => false, ] @@ -297,19 +271,6 @@ function (Options $options, $value) { $resolver->setAllowedTypes('context', ['array']); $resolver->setAllowedTypes('json_buffering', ['boolean']); - - $resolver->setAllowedTypes('process_options', ['array']); - $resolver->setNormalizer( - 'process_options', - static function (Options $options, array $value): array { - if ([] !== $value) { - // Deprecated option, removed in v6.0: a non-empty value is not supported anymore - throw new InvalidArgumentException('Deprecated option, please contact support for help'); - } - - return $value; - } - ); } /** diff --git a/tests/DependencyInjection/Compiler/CheckSerializerCompilerPassTest.php b/tests/DependencyInjection/Compiler/CheckSerializerCompilerPassTest.php deleted file mode 100644 index 58797805..00000000 --- a/tests/DependencyInjection/Compiler/CheckSerializerCompilerPassTest.php +++ /dev/null @@ -1,59 +0,0 @@ -expectException(AutowiringFailedException::class); - - self::ignoreDeprecations(static fn (): CheckSerializerCompilerPass => new CheckSerializerCompilerPass())->process(new ContainerBuilder()); - } - - #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] - public function testSerializerIsFound(): void - { - $container = new ContainerBuilder(); - $container->register('serializer', \stdClass::class); - - self::ignoreDeprecations(static fn (): CheckSerializerCompilerPass => new CheckSerializerCompilerPass())->process($container); - } -} diff --git a/tests/DependencyInjection/LoadExtensionTest.php b/tests/DependencyInjection/LoadExtensionTest.php index d150a62f..2ad97dfd 100644 --- a/tests/DependencyInjection/LoadExtensionTest.php +++ b/tests/DependencyInjection/LoadExtensionTest.php @@ -220,18 +220,4 @@ public function testTheDashesOfTheGenericTransformerCodesAreKept(): void self::assertTrue($container->hasDefinition(GenericTransformer::class.'\\to-upper')); self::assertSame([['code' => 'to-upper']], $container->getDefinition(GenericTransformer::class.'\\to-upper')->getTag('cleverage.transformer')); } - - public function testTheDataQueueListenerIsDeprecated(): void - { - $container = new ContainerBuilder(); - ExtensionLoader::load([], $container); - - $id = 'cleverage_process.event_listener.data_queue'; - $definition = $container->getDefinition($id); - self::assertTrue($definition->isDeprecated()); - $deprecation = $definition->getDeprecation($id); - self::assertSame('cleverage/process-bundle', $deprecation['package']); - self::assertSame('5.4', $deprecation['version']); - self::assertStringStartsWith(\sprintf('The "%s" service is deprecated, it will be removed in v6.0', $id), $deprecation['message']); - } } diff --git a/tests/Model/ProcessStateTest.php b/tests/Model/ProcessStateTest.php index 2aabf337..0fc69490 100644 --- a/tests/Model/ProcessStateTest.php +++ b/tests/Model/ProcessStateTest.php @@ -77,29 +77,6 @@ public function testContextualizedOptionsUseADefaultResolver(): void self::assertSame(['foo' => 'baz'], $state->getContextualizedOptions()); } - public function testReturnCodeIsDeprecated(): void - { - $state = $this->createState(); - $deprecations = []; - set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { - $deprecations[] = $errstr; - - return true; - }, \E_USER_DEPRECATED); - try { - $state->setReturnCode(2); - $returnCode = $state->getReturnCode(); - } finally { - restore_error_handler(); - } - - $this->assertSame(2, $returnCode); - $this->assertSame([ - 'Since cleverage/process-bundle 5.10: The "CleverAge\\ProcessBundle\\Model\\ProcessState::setReturnCode()" method is deprecated: it is used nowhere (the exit code of the command does not depend on it) and will be removed in 6.0.', - 'Since cleverage/process-bundle 5.10: The "CleverAge\\ProcessBundle\\Model\\ProcessState::getReturnCode()" method is deprecated: it is used nowhere and will be removed in 6.0.', - ], $deprecations); - } - private function createState(): ProcessState { $processConfiguration = new ProcessConfiguration('test', []); diff --git a/tests/Model/SubprocessInstanceTest.php b/tests/Model/SubprocessInstanceTest.php index 52bf7b13..648c8ed4 100644 --- a/tests/Model/SubprocessInstanceTest.php +++ b/tests/Model/SubprocessInstanceTest.php @@ -18,7 +18,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpKernel\KernelInterface; #[CoversClass(SubprocessInstance::class)] #[UsesClass(TemporaryFile::class)] @@ -126,34 +125,6 @@ public function testMissingConsoleThrows(): void (new SubprocessInstance($this->projectDir.'/missing', 'child', null))->buildProcess(); } - public function testPassingTheKernelIsDeprecated(): void - { - $kernel = $this->createStub(KernelInterface::class); - $kernel->method('getProjectDir')->willReturn($this->projectDir); - $kernel->method('getEnvironment')->willReturn('prod'); - $kernel->method('getLogDir')->willReturn($this->projectDir.'/var/log'); - $deprecations = []; - set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { - $deprecations[] = $errstr; - - return true; - }, \E_USER_DEPRECATED); - try { - $subprocess = new SubprocessInstance($kernel, 'child', null); - } finally { - restore_error_handler(); - } - - $this->assertSame( - ['Since cleverage/process-bundle 5.4: Passing a "Symfony\Component\HttpKernel\KernelInterface" to "CleverAge\ProcessBundle\Model\SubprocessInstance::__construct()" is deprecated, pass the path of the console and the environment instead. The argument will only accept a string in v6.0.'], - $deprecations - ); - $commandLine = $subprocess->buildProcess()->getProcess()->getCommandLine(); - $this->assertStringContainsString("'{$this->projectDir}/bin/console' '--env=prod'", $commandLine); - // The log directory of the kernel is no longer created - $this->assertDirectoryDoesNotExist($this->projectDir.'/var'); - } - private function runWithJsonBuffering(): SubprocessInstance { $subprocess = (new SubprocessInstance($this->projectDir.'/bin/console', 'child', null, [], [SubprocessInstance::OPTION_JSON_BUFFERING => true])) diff --git a/tests/Task/Process/CommandRunnerTaskTest.php b/tests/Task/Process/CommandRunnerTaskTest.php index f339ac4f..281c1a14 100644 --- a/tests/Task/Process/CommandRunnerTaskTest.php +++ b/tests/Task/Process/CommandRunnerTaskTest.php @@ -20,7 +20,6 @@ use CleverAge\ProcessBundle\Model\ProcessState; use CleverAge\ProcessBundle\Task\Process\CommandRunnerTask; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -84,26 +83,6 @@ public function testProjectDirIsTheDefaultCwd(): void $this->assertSame(realpath(sys_get_temp_dir()).\PHP_EOL, $state->getOutput()); } - public function testPassingTheKernelIsDeprecated(): void - { - $kernel = $this->createStub(KernelInterface::class); - $kernel->method('getProjectDir')->willReturn(sys_get_temp_dir()); - $task = null; - - $deprecations = $this->collectDeprecations(static function () use ($kernel, &$task): void { - $task = new CommandRunnerTask($kernel); - }); - - $this->assertSame( - ['Since cleverage/process-bundle 5.4: Passing a "Symfony\Component\HttpKernel\KernelInterface" to "CleverAge\ProcessBundle\Task\Process\CommandRunnerTask::__construct()" is deprecated, pass the project directory instead. The argument will only accept a string in v6.0.'], - $deprecations - ); - $this->assertInstanceOf(CommandRunnerTask::class, $task); - $state = $this->createState(['commandline' => 'pwd']); - $task->execute($state); - $this->assertSame(realpath(sys_get_temp_dir()).\PHP_EOL, $state->getOutput()); - } - public function testProcessOptionsArePassedToProcess(): void { $state = $this->createState([ @@ -140,28 +119,6 @@ private function createTask(): CommandRunnerTask return new CommandRunnerTask(sys_get_temp_dir()); } - /** - * @param callable(): mixed $callback - * - * @return list - */ - private function collectDeprecations(callable $callback): array - { - $deprecations = []; - set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { - $deprecations[] = $errstr; - - return true; - }, \E_USER_DEPRECATED); - try { - $callback(); - } finally { - restore_error_handler(); - } - - return $deprecations; - } - /** * @param array $options */ diff --git a/tests/Task/Process/ProcessLauncherTaskTest.php b/tests/Task/Process/ProcessLauncherTaskTest.php index 8e9150ff..2d987f2d 100644 --- a/tests/Task/Process/ProcessLauncherTaskTest.php +++ b/tests/Task/Process/ProcessLauncherTaskTest.php @@ -27,7 +27,7 @@ use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; -use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; #[\PHPUnit\Framework\Attributes\CoversClass(ProcessLauncherTask::class)] #[\PHPUnit\Framework\Attributes\CoversMethod(ProcessLauncherTask::class, 'configureOptions')] @@ -49,18 +49,14 @@ public function testDefaultOptionsAreResolved(): void $this->createTask()->initialize($this->createState(['process' => 'child'])); } - #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] - public function testEmptyProcessOptionsAreAccepted(): void - { - $this->createTask()->initialize($this->createState(['process' => 'child', 'process_options' => []])); - } - - public function testNonEmptyProcessOptionsThrow(): void + /** + * The "process_options" option, deprecated (a non-empty value threw), is removed. + */ + public function testProcessOptionsIsUndefined(): void { - $state = $this->createState(['process' => 'child', 'process_options' => ['foo' => 'bar']]); + $state = $this->createState(['process' => 'child', 'process_options' => []]); - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Deprecated option'); + $this->expectException(UndefinedOptionsException::class); $this->createTask()->initialize($state); } @@ -72,28 +68,6 @@ public function testUnknownProcessThrows(): void $this->createTask()->initialize($state); } - public function testPassingTheKernelIsDeprecated(): void - { - $kernel = $this->createStub(KernelInterface::class); - $kernel->method('getProjectDir')->willReturn('/app'); - $kernel->method('getEnvironment')->willReturn('prod'); - $task = null; - - $deprecations = $this->collectDeprecations(function () use ($kernel, &$task): void { - $task = new ProcessLauncherTask(new NullLogger(), $this->createRegistry(), $kernel); - }); - - $this->assertSame( - ['Since cleverage/process-bundle 5.4: Passing a "Symfony\Component\HttpKernel\KernelInterface" to "CleverAge\ProcessBundle\Task\Process\ProcessLauncherTask::__construct()" is deprecated, pass the path of the console and the environment instead. The argument will only accept a string in v6.0.'], - $deprecations - ); - $this->assertInstanceOf(ProcessLauncherTask::class, $task); - $this->assertSame(['/app/bin/console', 'prod'], [ - (new \ReflectionProperty($task, 'consolePath'))->getValue($task), - (new \ReflectionProperty($task, 'environment'))->getValue($task), - ]); - } - public function testJsonBufferingOutputsThePathOfTheWrittenBuffer(): void { [$task, $state] = $this->launch('write'); @@ -366,28 +340,6 @@ private function createRegistry(): ProcessConfigurationRegistry return $registry; } - /** - * @param callable(): mixed $callback - * - * @return list - */ - private function collectDeprecations(callable $callback): array - { - $deprecations = []; - set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { - $deprecations[] = $errstr; - - return true; - }, \E_USER_DEPRECATED); - try { - $callback(); - } finally { - restore_error_handler(); - } - - return $deprecations; - } - /** * @param array $options */