Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/TaskConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 7 additions & 8 deletions src/Manager/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/Task/Event/EventDispatcherTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Transformer/CallbackTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}

Expand Down
9 changes: 6 additions & 3 deletions src/Transformer/MappingTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions tests/Configuration/TaskConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\ProcessBundle\Tests\Configuration;

use CleverAge\ProcessBundle\Configuration\TaskConfiguration;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(TaskConfiguration::class)]
class TaskConfigurationTest extends TestCase
{
public function testGetErrorsIsDeprecated(): void
{
$taskConfiguration = new TaskConfiguration('task', 'service', [], errorOutputs: ['error']);

$deprecations = [];
set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool {
$deprecations[] = $errstr;

return true;
}, \E_USER_DEPRECATED);
try {
$errors = $taskConfiguration->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
);
}
}
2 changes: 1 addition & 1 deletion tests/Manager/ProcessManagerInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/Task/Event/EventDispatcherTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/Transformer/CallbackTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/Transformer/MappingTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading