From 56c8c92aea88babb70d4b098af9fcf2564f5a644 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Wed, 14 Oct 2026 15:34:12 +0200 Subject: [PATCH] #273 - Use trigger_deprecation() instead of trigger_error(E_USER_DEPRECATED) - Require symfony/deprecation-contracts (^2.5|^3, already installed through the Symfony components). - Replace the 5 @trigger_error(..., E_USER_DEPRECATED) calls by trigger_deprecation('cleverage/process-bundle', , ...), with the version that introduced each deprecation: 2.0.4 (CallbackTransformer additional_parameters, TaskConfiguration::getErrors()), 5.1 (EventDispatcherTask class name listeners #189, initialization failure #222), 5.2 (MappingTransformer array target path #117). "since v5" removed from the messages, now given by the prefix. - Tests: full messages of every deprecation (new TaskConfigurationTest and CallbackTransformerTest::testAdditionalParametersAreDeprecated). Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + composer.json | 1 + src/Configuration/TaskConfiguration.php | 2 +- src/Manager/ProcessManager.php | 15 +++--- src/Task/Event/EventDispatcherTask.php | 13 +++--- src/Transformer/CallbackTransformer.php | 7 +-- src/Transformer/MappingTransformer.php | 9 ++-- tests/Configuration/TaskConfigurationTest.php | 46 +++++++++++++++++++ .../ProcessManagerInitializationTest.php | 2 +- tests/Task/Event/EventDispatcherTaskTest.php | 6 ++- tests/Transformer/CallbackTransformerTest.php | 28 +++++++++++ tests/Transformer/MappingTransformerTest.php | 2 +- 12 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 tests/Configuration/TaskConfigurationTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index efe38934..55757f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ## Changes +* [#273](https://github.com/cleverage/process-bundle/issues/273) Trigger the deprecations with `trigger_deprecation()` (`symfony/deprecation-contracts`, now required) instead of `@trigger_error(..., E_USER_DEPRECATED)`: the messages are prefixed with the package and the version that introduced the deprecation (e.g. `Since cleverage/process-bundle 5.1: ...`), as for the Symfony packages. Same `E_USER_DEPRECATED` level. Add tests. * [#270](https://github.com/cleverage/process-bundle/issues/270) Add a `.gitattributes`: the development files (`.docker/`, `.github/`, `tests/`, quality tools and PHPUnit configurations, `Makefile`…) are no longer part of the archive installed by Composer (`dist`). Remove the obsolete test fixtures of `src/Resources/tests/` (not used since the tests rewrite). * [#271](https://github.com/cleverage/process-bundle/issues/271) DependencyInjection: `CleverAgeProcessExtension::findServices()` loads the service definition files with a glob pattern instead of a `Finder` (same files), `Configuration` uses `arrayPrototype()` / `variablePrototype()` / `scalarPrototype()` instead of `prototype()` (same configuration tree). Add tests. * [#282](https://github.com/cleverage/process-bundle/issues/282) Require `psr/container` (`ProcessHelpCommand`), `ext-xmlreader` (`XmlStreamReaderTask`) and `ext-libxml` (`XmlFile`, `XmlStreamReaderTask`, `XpathEvaluatorTransformer`), used directly; add `symfony/cache` (used by the tests) to the dev requirements. diff --git a/composer.json b/composer.json index 2826889a..27d981f0 100644 --- a/composer.json +++ b/composer.json @@ -64,6 +64,7 @@ "psr/container": "^1.1|^2", "symfony/config": "^6.4|^7.4|^8", "symfony/console": "^6.4|^7.4|^8", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/dependency-injection": "^6.4|^7.4|^8", "symfony/event-dispatcher": "^6.4|^7.4|^8", "symfony/event-dispatcher-contracts": "^3", diff --git a/src/Configuration/TaskConfiguration.php b/src/Configuration/TaskConfiguration.php index f6b167ce..eea7aed0 100644 --- a/src/Configuration/TaskConfiguration.php +++ b/src/Configuration/TaskConfiguration.php @@ -129,7 +129,7 @@ public function getOutputs(): array #[\Deprecated(message: 'Use getErrorOutputs method instead')] public function getErrors(): array { - @trigger_error('Deprecated method, use getErrorOutputs instead', \E_USER_DEPRECATED); + trigger_deprecation('cleverage/process-bundle', '2.0.4', 'The "%s()" method is deprecated, use "getErrorOutputs()" instead.', __METHOD__); return $this->getErrorOutputs(); } diff --git a/src/Manager/ProcessManager.php b/src/Manager/ProcessManager.php index 7984bb6f..3c2ce0a4 100644 --- a/src/Manager/ProcessManager.php +++ b/src/Manager/ProcessManager.php @@ -276,14 +276,13 @@ protected function initialize(TaskConfiguration $taskConfiguration): void $this->taskLogger->critical($e->getMessage(), $logContext); $state->stop($e); // @deprecated since v5, in v6.0 the process will fail right away, before any task is executed - @trigger_error( - \sprintf( - 'The initialization of the task "%s" of the process "%s" has failed with message "%s". Going on with the process after an initialization failure is deprecated since v5: in v6.0, the process will fail before executing any task.', - $taskConfiguration->getCode(), - $state->getProcessConfiguration()->getCode(), - $e->getMessage(), - ), - \E_USER_DEPRECATED + trigger_deprecation( + 'cleverage/process-bundle', + '5.1', + 'The initialization of the task "%s" of the process "%s" has failed with message "%s". Going on with the process after an initialization failure is deprecated: in v6.0, the process will fail before executing any task.', + $taskConfiguration->getCode(), + $state->getProcessConfiguration()->getCode(), + $e->getMessage(), ); } } diff --git a/src/Task/Event/EventDispatcherTask.php b/src/Task/Event/EventDispatcherTask.php index 3f2b8e25..1e092e16 100644 --- a/src/Task/Event/EventDispatcherTask.php +++ b/src/Task/Event/EventDispatcherTask.php @@ -47,13 +47,12 @@ public function execute(ProcessState $state): void && EventDispatcherTaskEvent::class !== $options['event_name'] && $this->eventDispatcher->hasListeners(EventDispatcherTaskEvent::class) ) { - @trigger_error( - \sprintf( - 'Listening to "%s" for an EventDispatcherTask with the "event_name" option set is deprecated since v5 and will not work anymore in v6.0, listen to "%s" instead.', - EventDispatcherTaskEvent::class, - $options['event_name'], - ), - \E_USER_DEPRECATED + trigger_deprecation( + 'cleverage/process-bundle', + '5.1', + 'Listening to "%s" for an EventDispatcherTask with the "event_name" option set is deprecated and will not work anymore in v6.0, listen to "%s" instead.', + EventDispatcherTaskEvent::class, + $options['event_name'], ); $this->eventDispatcher->dispatch($event); } diff --git a/src/Transformer/CallbackTransformer.php b/src/Transformer/CallbackTransformer.php index a18e6ddd..2f17ef03 100644 --- a/src/Transformer/CallbackTransformer.php +++ b/src/Transformer/CallbackTransformer.php @@ -77,9 +77,10 @@ static function (Options $options, $value): callable { 'additional_parameters', static function (Options $options, $value) { if ($value) { - @trigger_error( - 'The "additional_parameters" option is deprecated. Use "right_parameters" instead.', - \E_USER_DEPRECATED + trigger_deprecation( + 'cleverage/process-bundle', + '2.0.4', + 'The "additional_parameters" option is deprecated. Use "right_parameters" instead.' ); } diff --git a/src/Transformer/MappingTransformer.php b/src/Transformer/MappingTransformer.php index dbfc5890..8076ae2a 100644 --- a/src/Transformer/MappingTransformer.php +++ b/src/Transformer/MappingTransformer.php @@ -115,9 +115,12 @@ public function transform(mixed $value, array $options = []): mixed $this->accessor->setValue($result, $targetProperty, $transformedValue); } elseif (\is_array($result)) { if (!$this->isSimplePropertyName($targetProperty)) { - @trigger_error( - "Setting the target property '{$targetProperty}' as a literal key of an array destination is deprecated, it will throw an \\UnexpectedValueException in v6.0. Use '[{$targetProperty}]' to keep a literal key, or the index notation for nested arrays (e.g. '[a][b]').", - \E_USER_DEPRECATED + trigger_deprecation( + 'cleverage/process-bundle', + '5.2', + "Setting the target property '%s' as a literal key of an array destination is deprecated, it will throw an \\UnexpectedValueException in v6.0. Use '[%s]' to keep a literal key, or the index notation for nested arrays (e.g. '[a][b]').", + $targetProperty, + $targetProperty ); } $result[$targetProperty] = $transformedValue; diff --git a/tests/Configuration/TaskConfigurationTest.php b/tests/Configuration/TaskConfigurationTest.php new file mode 100644 index 00000000..bbe36a47 --- /dev/null +++ b/tests/Configuration/TaskConfigurationTest.php @@ -0,0 +1,46 @@ +getErrors(); + } finally { + restore_error_handler(); + } + + self::assertSame(['error'], $errors); + // PHP 8.4+ also triggers its own deprecation for the #[\Deprecated] attribute + self::assertContains( + 'Since cleverage/process-bundle 2.0.4: The "CleverAge\ProcessBundle\Configuration\TaskConfiguration::getErrors()" method is deprecated, use "getErrorOutputs()" instead.', + $deprecations + ); + } +} diff --git a/tests/Manager/ProcessManagerInitializationTest.php b/tests/Manager/ProcessManagerInitializationTest.php index 373068e0..d01c7921 100644 --- a/tests/Manager/ProcessManagerInitializationTest.php +++ b/tests/Manager/ProcessManagerInitializationTest.php @@ -92,7 +92,7 @@ public function testNoDeprecationWithoutInitializationFailure(): void private function getExpectedDeprecation(): string { - return 'The initialization of the task "bad" of the process "test.process" has failed with message "Invalid configuration". Going on with the process after an initialization failure is deprecated since v5: in v6.0, the process will fail before executing any task.'; + return 'Since cleverage/process-bundle 5.1: The initialization of the task "bad" of the process "test.process" has failed with message "Invalid configuration". Going on with the process after an initialization failure is deprecated: in v6.0, the process will fail before executing any task.'; } private function execute(ProcessManager $processManager): void diff --git a/tests/Task/Event/EventDispatcherTaskTest.php b/tests/Task/Event/EventDispatcherTaskTest.php index f72ee729..3ba23388 100644 --- a/tests/Task/Event/EventDispatcherTaskTest.php +++ b/tests/Task/Event/EventDispatcherTaskTest.php @@ -78,8 +78,10 @@ public function testClassNameListenersAreStillCalledWithDeprecation(): void $this->execute($dispatcher, ['event_name' => 'myapp.myevent']); self::assertSame(['myapp.myevent', EventDispatcherTaskEvent::class], $this->calledListeners); - self::assertCount(1, $this->deprecations); - self::assertStringContainsString('listen to "myapp.myevent" instead', $this->deprecations[0]); + self::assertSame( + ['Since cleverage/process-bundle 5.1: Listening to "'.EventDispatcherTaskEvent::class.'" for an EventDispatcherTask with the "event_name" option set is deprecated and will not work anymore in v6.0, listen to "myapp.myevent" instead.'], + $this->deprecations + ); } public function testPassiveTaskOutputsInput(): void diff --git a/tests/Transformer/CallbackTransformerTest.php b/tests/Transformer/CallbackTransformerTest.php index af0d9d5a..3f88d162 100644 --- a/tests/Transformer/CallbackTransformerTest.php +++ b/tests/Transformer/CallbackTransformerTest.php @@ -90,6 +90,34 @@ public function testAdditionalParametersAreUsedAsRightParameters(): void self::assertSame('6-7-8', $transformer->transform('6', $options)); } + public function testAdditionalParametersAreDeprecated(): void + { + $transformer = new CallbackTransformer(); + $deprecations = []; + set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { + $deprecations[] = $errstr; + + return true; + }, \E_USER_DEPRECATED); + try { + $this->resolveOptions($transformer, [ + 'callback' => [self::class, 'doCallback'], + 'additional_parameters' => [7, 8], + ]); + $this->resolveOptions($transformer, [ + 'callback' => [self::class, 'doCallback'], + 'right_parameters' => [4], + ]); + } finally { + restore_error_handler(); + } + + self::assertSame( + ['Since cleverage/process-bundle 2.0.4: The "additional_parameters" option is deprecated. Use "right_parameters" instead.'], + $deprecations + ); + } + public function testAdditionalParametersAreIgnoredWhenRightParametersAreSet(): void { $transformer = new CallbackTransformer(); diff --git a/tests/Transformer/MappingTransformerTest.php b/tests/Transformer/MappingTransformerTest.php index d341c559..4b788ab3 100644 --- a/tests/Transformer/MappingTransformerTest.php +++ b/tests/Transformer/MappingTransformerTest.php @@ -486,7 +486,7 @@ public function testNonSimpleTargetPropertyOfAnArrayDestinationIsDeprecated(stri self::assertSame([$targetProperty => 'value'], $result); self::assertSame([ - "Setting the target property '{$targetProperty}' as a literal key of an array destination is deprecated, it will throw an \\UnexpectedValueException in v6.0. Use '[{$targetProperty}]' to keep a literal key, or the index notation for nested arrays (e.g. '[a][b]').", + "Since cleverage/process-bundle 5.2: Setting the target property '{$targetProperty}' as a literal key of an array destination is deprecated, it will throw an \\UnexpectedValueException in v6.0. Use '[{$targetProperty}]' to keep a literal key, or the index notation for nested arrays (e.g. '[a][b]').", ], $this->deprecations); }