diff --git a/CHANGELOG.md b/CHANGELOG.md index 035cff3c..73b52068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Latest * [#292](https://github.com/cleverage/process-bundle/issues/292) Apply the behaviours announced by the deprecations of v5: an exception thrown by the `initialize()` of a task makes the process fail before any task is executed, with a `ProcessFailedException` (#222); the `event_dispatcher` task no longer dispatches its event under the class name of the event too when `event_name` is set (#189); a target property of an array destination that is neither a simple property name nor an index notation (`address.city`) throws an `UnexpectedValueException` in the `mapping` transformer (#117); the `additional_parameters` option of the `callback` transformer is removed, use `right_parameters`; a negative `flush_every` of the `counter` task is rejected (#491) (see `UPGRADE.md`). Update documentation and tests. * [#279](https://github.com/cleverage/process-bundle/issues/279) The 109 classes marked `@final since 5.4` are `final` (engine, registries, models, configurations, events, `CleverAgeProcessBundle`, concrete tasks and transformers): they can no longer be extended nor doubled by PHPUnit. The services of the bundle are typed on `ProcessManagerInterface`, `ProcessConfigurationRegistryInterface` and `TransformerRegistryInterface`, so that a decorator is injected everywhere; `ProcessManagerInterface` declares `getProcessHistory()` and `getTaskConfiguration()`, `ProcessConfigurationRegistryInterface` declares `getProcessCodes()`, and both extend `ResetInterface` (a decorator receives the `kernel.reset` tag and must delegate `reset()`). `PregFilterTransformer::transform()` returns `?string`, the `$transformerRegistry` property of `TransformerTrait` is typed on `TransformerRegistryInterface`, `SplFile::readLine()` no longer has its unused `$length` parameter (see `UPGRADE.md`). Update documentation and tests. * [#505](https://github.com/cleverage/process-bundle/issues/505) Consistent names for the equivalent options of the tasks: `filename` is renamed `file_path` (`file_reader`, `file_writer`, `line_reader`) and `base_folder_path` is renamed `base_path` (`input_folder_browser`), without deprecation in 5.x; `input_folder_browser` adds a single `/` between a non-empty `base_path` and the input, as `input_csv_reader` does (see `UPGRADE.md`). Update documentation and tests. +* [#380](https://github.com/cleverage/process-bundle/issues/380) Executing a process while it is already running, by itself or through its sub-processes (`A → B → A` with `process_executor`), throws a `RecursiveProcessExecutionException` naming the chain of processes, before any event is dispatched for the rejected execution (deprecated since 5.6, it reset the states of the running process). The `error_strategy` of the `process_executor` task applies (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 5324bd0e..3fcff231 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -221,7 +221,14 @@ The former names of the codes with a dash, with underscores instead of dashes, a - the `additional_parameters` option of the `callback` transformer is removed (deprecated since 2.0.4): rename it `right_parameters`, an `UndefinedOptionsException` is thrown otherwise; - a negative `flush_every` option of the `counter` task is rejected with an `InvalidOptionsException` (it worked as - its absolute value, deprecated since 5.10): use a positive integer. + its absolute value, deprecated since 5.10): use a positive integer; +- executing a process while it is already running, by itself or through its sub-processes (`A → B → A` with the + `process_executor` task), throws a `RecursiveProcessExecutionException` (`Executing the process "A" while it is + already running (A -> B -> A) is not allowed...`), before any event is dispatched for the rejected execution (it + reset the states of the running process, deprecated since 5.6). In a `process_executor` task, its `error_strategy` + applies: with `stop` (default), the parent processes fail. Iterate with an iterable task instead of recursing, or use + the `process_launcher` task, which runs the process in a separate PHP process (not detected: bound the recursion + yourself). ### Final classes diff --git a/docs/04-advanced_workflow.md b/docs/04-advanced_workflow.md index a3332940..531d95a7 100644 --- a/docs/04-advanced_workflow.md +++ b/docs/04-advanced_workflow.md @@ -216,8 +216,8 @@ values when executing the parent process. This is a good way to split a big workflow into small, testable processes. Private processes (`public: false`) are hidden from `cleverage:process:list` (unless `--all` is used) but can still be executed. -Executing a process while it is already running, by itself or through its sub-processes, is deprecated and will throw -an exception in 6.0 (see the [ProcessExecutorTask](reference/tasks/process_executor_task.md#notes)). +Executing a process while it is already running, by itself or through its sub-processes, throws a +`RecursiveProcessExecutionException` (see the [ProcessExecutorTask](reference/tasks/process_executor_task.md#notes)). ## Events diff --git a/docs/reference/01-process_definition.md b/docs/reference/01-process_definition.md index 16f72f38..5e417cd6 100644 --- a/docs/reference/01-process_definition.md +++ b/docs/reference/01-process_definition.md @@ -74,7 +74,10 @@ when the container is compiled. **exclusive**: optional boolean (default is false). An execution of an exclusive process fails with a `ProcessAlreadyRunningException` while another execution of it is running, from the same PHP process or from another one sharing the lock store (cron entries, user interface, schedulers, Messenger workers): it is not executed, and the -failure is dispatched as any process failure (`EVENT_PROCESS_FAILED`). It requires the +failure is dispatched as any process failure (`EVENT_PROCESS_FAILED`). Executing it by itself or through its +sub-processes is rejected before its lock is requested, as for any process, with a +`RecursiveProcessExecutionException` and no event (see the +[ProcessExecutorTask](tasks/process_executor_task.md#notes)). It requires the [Lock component](https://symfony.com/doc/current/lock.html) (`composer require symfony/lock`, `lock.factory` service of the FrameworkBundle): an exclusive process without it is rejected when the container is compiled. diff --git a/docs/reference/tasks/process_executor_task.md b/docs/reference/tasks/process_executor_task.md index 15ee1098..54250c49 100644 --- a/docs/reference/tasks/process_executor_task.md +++ b/docs/reference/tasks/process_executor_task.md @@ -54,10 +54,12 @@ Notes * The `process` option is checked when the task is initialized: with an unknown process, the initialization fails, the error is logged and the parent process fails before any of its tasks is executed (see [initializable tasks](../../02-task_types.md#initializable-tasks)). -* Executing a process while it is already running, by itself or through its sub-processes (`A → B → A`), is - deprecated since 5.6 and will throw an exception in 6.0: a process has only one set of task instances and states, - which the second execution resets while the first one is running (the running process then returns the output of the - deepest execution). A deprecation naming the chain of processes (`A -> B -> A`) is triggered, and the execution goes - on. Iterate with an iterable task instead of recursing, or use the [ProcessLauncherTask](process_launcher_task.md), - which runs the process in a separate PHP process. Executing the same sub-process several times in a row (e.g. for - each input) is not concerned. +* Executing a process while it is already running, by itself or through its sub-processes (`A → B → A`), throws a + `RecursiveProcessExecutionException` naming the chain of processes (`A -> B -> A`): a process has only one set of + task instances and states, which a second execution would reset while the first one is running. The exception is + thrown before any event is dispatched for the rejected execution (the running process is not ended for the listeners + of the events, e.g. a user interface); the `error_strategy` of this task applies: with `stop` (default), the parent + processes fail, with `skip`, the input is skipped. Iterate with an iterable task instead of recursing, or use the + [ProcessLauncherTask](process_launcher_task.md), which runs the process in a separate PHP process (a recursion is not + detected there: bound it yourself). Executing the same sub-process several times in a row (e.g. for each input) is + not concerned. diff --git a/src/Exception/RecursiveProcessExecutionException.php b/src/Exception/RecursiveProcessExecutionException.php new file mode 100644 index 00000000..0583986f --- /dev/null +++ b/src/Exception/RecursiveProcessExecutionException.php @@ -0,0 +1,33 @@ + $runningProcessCodes codes of the processes being executed, a sub-process after its parent + */ + public static function create(string $processCode, array $runningProcessCodes): self + { + $chain = implode(' -> ', [...$runningProcessCodes, $processCode]); + + return new self( + "Executing the process \"{$processCode}\" while it is already running ({$chain}) is not allowed: a process has only one set of task instances and states." + ); + } +} diff --git a/src/Manager/ProcessManager.php b/src/Manager/ProcessManager.php index c5f3d933..308751f4 100644 --- a/src/Manager/ProcessManager.php +++ b/src/Manager/ProcessManager.php @@ -22,6 +22,7 @@ use CleverAge\ProcessBundle\Exception\ProcessAlreadyRunningException; use CleverAge\ProcessBundle\Exception\ProcessFailedException; use CleverAge\ProcessBundle\Exception\ProcessStoppedException; +use CleverAge\ProcessBundle\Exception\RecursiveProcessExecutionException; use CleverAge\ProcessBundle\Exception\RuntimeException; use CleverAge\ProcessBundle\Exception\UnexpectedValueException; use CleverAge\ProcessBundle\Logger\ProcessLogger; @@ -74,7 +75,7 @@ final class ProcessManager implements ProcessManagerInterface /** * Codes of the processes being executed, a sub-process after its parent: a process has only one configuration (task - * instances and states), executing it again while it is running resets them. + * instances and states), executing it again while it is running is rejected. * * @var list */ @@ -162,6 +163,13 @@ public function getTaskConfiguration(): ?TaskConfiguration */ public function execute(string $processCode, mixed $input = null, array $context = []): mixed { + // Before any event: a failure event would end the execution of the running process for its listeners (e.g. + // the user interface). The codes of the running processes are the codes of their configurations, as the one + // given (an unknown process is never running: it fails as usual, with its events) + if (\in_array($processCode, $this->runningProcessCodes, true)) { + throw RecursiveProcessExecutionException::create($processCode, $this->runningProcessCodes); + } + $parentProcessHistory = $this->processHistory; $parentTaskConfiguration = $this->taskConfiguration; try { @@ -172,16 +180,6 @@ public function execute(string $processCode, mixed $input = null, array $context $this->processLogger->debug('Process start'); $code = $this->processConfigurationRegistry->getProcessConfiguration($processCode)->getCode(); - // @deprecated since 5.6, in v6.0 an exception will be thrown - if (\in_array($code, $this->runningProcessCodes, true)) { - trigger_deprecation( - 'cleverage/process-bundle', - '5.6', - 'Executing the process "%s" while it is already running (%s) is deprecated: it resets the states and task instances of the running process. In v6.0, an exception will be thrown.', - $code, - implode(' -> ', [...$this->runningProcessCodes, $code]), - ); - } // After the start event: the failure of an exclusive process already running is dispatched as any failure $lock = $this->acquireLock($code); $this->runningProcessCodes[] = $code; diff --git a/src/Manager/ProcessManagerInterface.php b/src/Manager/ProcessManagerInterface.php index 99d5b627..6bb3ab4e 100644 --- a/src/Manager/ProcessManagerInterface.php +++ b/src/Manager/ProcessManagerInterface.php @@ -16,6 +16,7 @@ use CleverAge\ProcessBundle\Configuration\TaskConfiguration; use CleverAge\ProcessBundle\Exception\MissingProcessException; use CleverAge\ProcessBundle\Exception\ProcessFailedException; +use CleverAge\ProcessBundle\Exception\RecursiveProcessExecutionException; use CleverAge\ProcessBundle\Model\ProcessHistory; use Symfony\Contracts\Service\ResetInterface; @@ -30,8 +31,10 @@ interface ProcessManagerInterface extends ResetInterface * * @param array $context * - * @throws MissingProcessException when the process does not exist - * @throws ProcessFailedException when a task fails with the "stop" error strategy + * @throws MissingProcessException when the process does not exist + * @throws ProcessFailedException when a task fails with the "stop" error strategy + * @throws RecursiveProcessExecutionException when the process is already running (by itself or through its + * sub-processes), before any event is dispatched */ public function execute(string $processCode, mixed $input = null, array $context = []): mixed; diff --git a/tests/Manager/ProcessManagerExclusiveTest.php b/tests/Manager/ProcessManagerExclusiveTest.php index a29f7a2d..dabb4fcb 100644 --- a/tests/Manager/ProcessManagerExclusiveTest.php +++ b/tests/Manager/ProcessManagerExclusiveTest.php @@ -20,6 +20,7 @@ use CleverAge\ProcessBundle\Exception\LogicException; use CleverAge\ProcessBundle\Exception\ProcessAlreadyRunningException; use CleverAge\ProcessBundle\Exception\ProcessFailedException; +use CleverAge\ProcessBundle\Exception\RecursiveProcessExecutionException; use CleverAge\ProcessBundle\Logger\AbstractLogger; use CleverAge\ProcessBundle\Logger\ProcessLogger; use CleverAge\ProcessBundle\Logger\TaskLogger; @@ -45,6 +46,8 @@ #[CoversClass(ProcessManager::class)] #[CoversClass(ProcessAlreadyRunningException::class)] #[UsesClass(ProcessFailedException::class)] +#[UsesClass(RecursiveProcessExecutionException::class)] +#[UsesClass(LogicException::class)] #[UsesClass(TaskRegistry::class)] #[UsesClass(ProcessConfiguration::class)] #[UsesClass(TaskConfiguration::class)] @@ -105,6 +108,32 @@ public function testExclusiveProcessFailsWhileItIsRunning(): void self::assertSame([1, 2, 3], $this->recorded, 'The running execution goes on'); } + /** + * An exclusive process executed by itself is rejected as any process already running, before its lock is + * requested: no failure is dispatched for the rejected execution, the running one goes on. + */ + public function testExclusiveProcessExecutedByItselfIsRejectedBeforeTheLock(): void + { + $processManager = $this->createProcessManager(new LockFactory(new InMemoryStore())); + $error = null; + $this->onRecord = static function (mixed $item) use ($processManager, &$error): void { + if (2 !== $item) { + return; + } + try { + $processManager->execute('test.exclusive'); + } catch (\Throwable $exception) { + $error = $exception; + } + }; + + $processManager->execute('test.exclusive'); + + self::assertInstanceOf(RecursiveProcessExecutionException::class, $error); + self::assertSame([], $this->failedEventErrors); + self::assertSame([1, 2, 3], $this->recorded, 'The running execution goes on'); + } + /** * The lock is released at the end of the process, succeeded or failed. */ diff --git a/tests/Manager/ProcessManagerRecursionTest.php b/tests/Manager/ProcessManagerRecursionTest.php index c5a8d9a5..4486af2a 100644 --- a/tests/Manager/ProcessManagerRecursionTest.php +++ b/tests/Manager/ProcessManagerRecursionTest.php @@ -17,7 +17,9 @@ use CleverAge\ProcessBundle\Configuration\TaskConfiguration; use CleverAge\ProcessBundle\Context\ContextualOptionResolver; use CleverAge\ProcessBundle\Event\ProcessEvent; +use CleverAge\ProcessBundle\Exception\MissingProcessException; use CleverAge\ProcessBundle\Exception\ProcessFailedException; +use CleverAge\ProcessBundle\Exception\RecursiveProcessExecutionException; use CleverAge\ProcessBundle\Logger\AbstractLogger; use CleverAge\ProcessBundle\Logger\ProcessLogger; use CleverAge\ProcessBundle\Logger\TaskLogger; @@ -41,16 +43,21 @@ /** * A process has only one configuration (task instances and states): executing it while it is running (directly or - * through sub-processes) resets them, which is deprecated. Executing the same sub-process several times in a row, or a - * process again once it has ended, is not concerned. + * through sub-processes) would reset them: it is rejected with an exception, before any event is dispatched for the + * rejected execution. Executing the same sub-process several times in a row, or a process again once it has ended, is + * not concerned. */ #[\PHPUnit\Framework\Attributes\CoversClass(ProcessManager::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(RecursiveProcessExecutionException::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessConfiguration::class)] #[\PHPUnit\Framework\Attributes\UsesClass(TaskRegistry::class)] #[\PHPUnit\Framework\Attributes\UsesClass(TaskConfiguration::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ContextualOptionResolver::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessEvent::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessFailedException::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(MissingProcessException::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Configuration\DidYouMean::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Exception\LogicException::class)] #[\PHPUnit\Framework\Attributes\UsesClass(AbstractLogger::class)] #[\PHPUnit\Framework\Attributes\UsesClass(AbstractConfigurableTask::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessHistory::class)] @@ -73,9 +80,11 @@ class ProcessManagerRecursionTest extends TestCase private int $recursions = 0; /** + * Events dispatched by the process manager, as " ". + * * @var list */ - private array $deprecations = []; + private array $events = []; protected function setUp(): void { @@ -104,6 +113,16 @@ protected function setUp(): void 'test.stopped' => $this->createProcessConfiguration([ 'stop' => $this->createTaskConfiguration('@test.stopped.stop'), ]), + 'test.executor.stop' => $this->createProcessConfiguration([ + 'iterate' => $this->createTaskConfiguration('@test.executor.stop.iterate', ['output' => [1, 2]], ['execute']), + 'execute' => $this->createTaskConfiguration('@test.executor.stop.execute', ['process' => 'test.executor.stop'], ['aggregate'], 'stop'), + 'aggregate' => $this->createTaskConfiguration('@test.executor.stop.aggregate'), + ], 'aggregate'), + 'test.executor.skip' => $this->createProcessConfiguration([ + 'iterate' => $this->createTaskConfiguration('@test.executor.skip.iterate', ['output' => [1, 2]], ['execute']), + 'execute' => $this->createTaskConfiguration('@test.executor.skip.execute', ['process' => 'test.executor.skip'], ['aggregate'], 'skip'), + 'aggregate' => $this->createTaskConfiguration('@test.executor.skip.aggregate'), + ], 'aggregate'), ], 'stop' ); @@ -147,17 +166,17 @@ public function execute(ProcessState $state): void } }); $container->set('test.stopped.stop', new StopTask()); + foreach (['stop', 'skip'] as $strategy) { + $container->set("test.executor.{$strategy}.iterate", new ConstantIterableOutputTask()); + $container->set("test.executor.{$strategy}.execute", new ProcessExecutorTask($this->processManager, $registry, new NullLogger())); + $container->set("test.executor.{$strategy}.aggregate", new AggregateIterableTask()); + } - set_error_handler(function (int $errno, string $errstr): bool { - $this->deprecations[] = $errstr; - - return true; - }, \E_USER_DEPRECATED); - } - - protected function tearDown(): void - { - restore_error_handler(); + foreach ([ProcessEvent::EVENT_PROCESS_STARTED, ProcessEvent::EVENT_PROCESS_ENDED, ProcessEvent::EVENT_PROCESS_FAILED] as $eventName) { + $this->eventDispatcher->addListener($eventName, function (ProcessEvent $event) use ($eventName): void { + $this->events[] = "{$eventName} {$event->getProcessCode()}"; + }); + } } public function recurse(string $processCode): int @@ -170,34 +189,87 @@ public function recurse(string $processCode): int return 1 + (int) $this->processManager->execute($processCode); } - public function testAProcessExecutingItselfIsDeprecated(): void + public function testAProcessExecutingItselfIsRejected(): void { $this->recursions = 2; - // The execution goes on as before: the states of the running process are reset, its output is the deepest one - self::assertSame(0, $this->processManager->execute('test.recursive')); - self::assertSame(0, $this->recursions); + try { + $this->processManager->execute('test.recursive'); + self::fail('No exception thrown'); + } catch (ProcessFailedException $exception) { + $previous = $exception->getPrevious(); + self::assertInstanceOf(RecursiveProcessExecutionException::class, $previous); + self::assertSame( + 'Executing the process "test.recursive" while it is already running (test.recursive -> test.recursive) is not allowed: a process has only one set of task instances and states.', + $previous->getMessage() + ); + } + self::assertSame(1, $this->recursions, 'Rejected at the first recursion'); + // No event for the rejected execution: only the running process fails, once self::assertSame([ - $this->getExpectedDeprecation('test.recursive', 'test.recursive -> test.recursive'), - $this->getExpectedDeprecation('test.recursive', 'test.recursive -> test.recursive -> test.recursive'), - ], $this->deprecations); + ProcessEvent::EVENT_PROCESS_STARTED.' test.recursive', + ProcessEvent::EVENT_PROCESS_FAILED.' test.recursive', + ], $this->events); } - public function testAProcessExecutedAgainThroughASubProcessIsDeprecated(): void + public function testAProcessExecutedAgainThroughASubProcessIsRejected(): void { $this->recursions = 2; + try { + $this->processManager->execute('test.a'); + self::fail('No exception thrown'); + } catch (ProcessFailedException $exception) { + // The failure of test.b, thrown by the task of test.a that executes it + $subProcessFailure = $exception->getPrevious(); + self::assertInstanceOf(ProcessFailedException::class, $subProcessFailure); + $previous = $subProcessFailure->getPrevious(); + self::assertInstanceOf(RecursiveProcessExecutionException::class, $previous); + self::assertStringStartsWith( + 'Executing the process "test.a" while it is already running (test.a -> test.b -> test.a) is not allowed', + $previous->getMessage() + ); + } + self::assertSame([ + ProcessEvent::EVENT_PROCESS_STARTED.' test.a', + ProcessEvent::EVENT_PROCESS_STARTED.' test.b', + ProcessEvent::EVENT_PROCESS_FAILED.' test.b', + ProcessEvent::EVENT_PROCESS_FAILED.' test.a', + ], $this->events); + + // The running processes have been forgotten: they can be executed again + $this->recursions = 0; self::assertSame(0, $this->processManager->execute('test.a')); - self::assertSame(0, $this->recursions); + } + + public function testAProcessExecutorExecutingItsProcessFailsWithTheStopStrategy(): void + { + try { + $this->processManager->execute('test.executor.stop'); + self::fail('No exception thrown'); + } catch (ProcessFailedException $exception) { + self::assertInstanceOf(RecursiveProcessExecutionException::class, $exception->getPrevious()); + } self::assertSame([ - $this->getExpectedDeprecation('test.a', 'test.a -> test.b -> test.a'), - ], $this->deprecations); + ProcessEvent::EVENT_PROCESS_STARTED.' test.executor.stop', + ProcessEvent::EVENT_PROCESS_FAILED.' test.executor.stop', + ], $this->events); } - public function testTheSameSubProcessExecutedSeveralTimesInARowIsNotDeprecated(): void + public function testAProcessExecutorExecutingItsProcessSkipsTheItemWithTheSkipStrategy(): void + { + // Each item is skipped, nothing reaches the aggregation + $this->processManager->execute('test.executor.skip'); + + self::assertSame([ + ProcessEvent::EVENT_PROCESS_STARTED.' test.executor.skip', + ProcessEvent::EVENT_PROCESS_ENDED.' test.executor.skip', + ], $this->events); + } + + public function testTheSameSubProcessCanBeExecutedSeveralTimesInARow(): void { self::assertSame(['child 1', 'child 2', 'child 3'], $this->processManager->execute('test.parent')); - self::assertSame([], $this->deprecations); } /** @@ -211,7 +283,7 @@ public static function provideListenerEvents(): iterable } #[DataProvider('provideListenerEvents')] - public function testAListenerExecutingTheProcessAgainIsNotDeprecated(string $eventName, string $processCode): void + public function testAListenerCanExecuteTheProcessAgain(string $eventName, string $processCode): void { $executions = 0; $this->eventDispatcher->addListener($eventName, function () use ($processCode, &$executions): void { @@ -230,10 +302,9 @@ public function testAListenerExecutingTheProcessAgainIsNotDeprecated(string $eve } self::assertSame(2, $executions); - self::assertSame([], $this->deprecations); } - public function testAProcessExecutedAgainAfterAFailureIsNotDeprecated(): void + public function testAProcessCanBeExecutedAgainAfterAFailure(): void { for ($i = 0; $i < 2; ++$i) { try { @@ -243,14 +314,29 @@ public function testAProcessExecutedAgainAfterAFailureIsNotDeprecated(): void self::assertSame('Failure', $exception->getPrevious()?->getMessage()); } } - self::assertSame([], $this->deprecations); } - public function testAProcessExecutedAgainAfterAStopIsNotDeprecated(): void + public function testAProcessCanBeExecutedAgainAfterAStop(): void { self::assertNull($this->processManager->execute('test.stopped')); self::assertNull($this->processManager->execute('test.stopped')); - self::assertSame([], $this->deprecations); + } + + /** + * An unknown process is never running: it fails as before, with its events. + */ + public function testAnUnknownProcessFailsWithItsEvents(): void + { + try { + $this->processManager->execute('test.unknown'); + self::fail('No exception thrown'); + } catch (MissingProcessException) { + } + + self::assertSame([ + ProcessEvent::EVENT_PROCESS_STARTED.' test.unknown', + ProcessEvent::EVENT_PROCESS_FAILED.' test.unknown', + ], $this->events); } public function testResetForgetsTheRunningProcesses(): void @@ -260,12 +346,6 @@ public function testResetForgetsTheRunningProcesses(): void $this->processManager->reset(); self::assertSame('child 0', $this->processManager->execute('test.child', 0)); - self::assertSame([], $this->deprecations); - } - - private function getExpectedDeprecation(string $processCode, string $chain): string - { - return "Since cleverage/process-bundle 5.6: Executing the process \"{$processCode}\" while it is already running ({$chain}) is deprecated: it resets the states and task instances of the running process. In v6.0, an exception will be thrown."; } /** @@ -292,7 +372,7 @@ private function createProcessConfiguration(array $tasks, ?string $endPoint = nu * * @return array */ - private function createTaskConfiguration(string $service, array $options = [], array $outputs = []): array + private function createTaskConfiguration(string $service, array $options = [], array $outputs = [], ?string $errorStrategy = null): array { return [ 'service' => $service, @@ -301,7 +381,7 @@ private function createTaskConfiguration(string $service, array $options = [], a 'help' => '', 'outputs' => $outputs, 'error_outputs' => [], - 'error_strategy' => null, + 'error_strategy' => $errorStrategy, 'log_level' => null, ]; }