From fcee0adb4d07132ad195b43194d3e0123bbe5d98 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Tue, 3 Nov 2026 11:37:59 +0100 Subject: [PATCH] #412 - Keep the dashes of the process, task and generic transformer codes, deprecate their former name with underscores Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + UPGRADE.md | 16 +++ config/services/registry.yaml | 1 + docs/reference/01-process_definition.md | 4 + .../03-generic_transformers_definition.md | 3 +- src/Configuration/DeprecatedCodeAliases.php | 47 ++++++++ .../CleverAgeProcessExtension.php | 8 ++ src/DependencyInjection/Configuration.php | 6 + src/Registry/ProcessConfigurationRegistry.php | 107 +++++++++++++++++- src/Registry/TransformerRegistry.php | 20 ++++ tests/Command/ExecuteProcessCommandTest.php | 1 + tests/Command/ListProcessCommandTest.php | 1 + .../DeprecatedCodeAliasesTest.php | 34 ++++++ .../CleverAgeProcessExtensionTest.php | 20 ++++ .../DependencyInjection/ConfigurationTest.php | 23 ++++ .../ProcessConfigurationRegistryTest.php | 59 ++++++++++ tests/Registry/TransformerRegistryTest.php | 29 +++++ .../Task/Process/ProcessExecutorTaskTest.php | 1 + 18 files changed, 378 insertions(+), 3 deletions(-) create mode 100644 src/Configuration/DeprecatedCodeAliases.php create mode 100644 tests/Configuration/DeprecatedCodeAliasesTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 78674c50..9c7e59c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Latest * [#392](https://github.com/cleverage/process-bundle/issues/392) Documentation: reset of the process configurations between two messages of a worker (`kernel.reset`, #355), permissions of the JSON buffer of `process_launcher`, `ProcessManager` subclasses in `UPGRADE.md` (v5.5), broken link in the CHANGELOG. ## Fixes +* [#412](https://github.com/cleverage/process-bundle/issues/412) The codes of the processes, of their tasks and of the generic transformers keep their dashes (`normalizeKeys(false)`): the Symfony configuration replaced them by underscores, while the references to them kept the dash and failed (`Unknown process demo.x-y`, `No task configuration with code : next-task`, `No transformer with code : to-upper`). Their former name (with underscores) still works, deprecated since 5.7, until v6.0 (see `UPGRADE.md`). Update documentation, add tests. * [#408](https://github.com/cleverage/process-bundle/issues/408) Regular expressions of `preg_match`, `preg_filter`, `slugify` (`replace`) and of the conditions (`match_regexp`, `not_match_regexp` of `filter`, `column_aggregator`, `array_filter`, `unset`): an invalid pattern is rejected when the options are resolved (`InvalidOptionsException`), instead of a PHP warning with the first value then "no match"; a PCRE error while matching (invalid UTF-8 with the `u` modifier, backtracking limit) throws an `UnexpectedValueException`, instead of being taken for "no match" (both `match_regexp` and `not_match_regexp` excluded the input). Update documentation, add tests. * [#410](https://github.com/cleverage/process-bundle/issues/410) `xpath_evaluator`: the queries are evaluated with `\DOMXPath::evaluate()`, an expression that does not return nodes (`count(...)`, `string(...)`, a comparison) returns its value (`float`, `string`, `bool`) instead of `null`; new `namespaces` option (prefix => URI) to query the elements of a namespace, including the default namespace of a document (documented). Documentation: the `mb_*` functions in the examples of `callback`, `generic_transformers` and `array_map`. Add tests. * [#402](https://github.com/cleverage/process-bundle/issues/402) `date_parser`: a date or a time out of range (`2024-02-31`, `25:61`), parsed by `\DateTime::createFromFormat()` with a warning and overflowing to the next month or day, throws an `UnexpectedValueException`, as documented for a value that cannot be parsed. A scalar (e.g. an `int` timestamp with the `U` format) or `\Stringable` input is cast to string, an array or another object throws an `UnexpectedValueException` instead of a `TypeError`. Update documentation, add tests. diff --git a/UPGRADE.md b/UPGRADE.md index 9386a384..38ae8ad9 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,6 +1,22 @@ Upgrade Guide ============= +## v5.7 + +### Dashes in the codes + +The codes of the processes, of their tasks and of the generic transformers keep their dashes. Before 5.7, the Symfony +configuration replaced them by underscores (unless the code also had an underscore): `demo.x-y` was registered as +`demo.x_y`, while the references to it kept the dash and failed (`Unknown process demo.x-y`, `No task configuration +with code : next-task`, `No transformer with code : to-upper`). Such codes now work as written, and `cleverage:process:list` +shows them with their dashes. + +If you used the former name (with underscores) of such a code, it still works but is deprecated since 5.7 +(`Since cleverage/process-bundle 5.7: Using the process "demo.x-y" by the name "demo.x_y"...`), and will not be found in +6.0: use the code as written in the configuration, in the commands (`cleverage:process:execute demo.x-y`), the +`process_executor` tasks, the task references (`outputs`, `error_outputs`, `entry_point`, `end_point`), the transformer +references and the applications storing process codes (e.g. the schedules of the UI bundle). + ## v5.6 Two deprecations, and some behaviours change: check the points below. diff --git a/config/services/registry.yaml b/config/services/registry.yaml index b8c70fbb..e581d2c9 100644 --- a/config/services/registry.yaml +++ b/config/services/registry.yaml @@ -20,6 +20,7 @@ services: public: false arguments: - ~ # Service locator of the transformers by code, see TransformerLocatorCompilerPass + - [] # Former names of the generic transformers whose code has a dash, see CleverAgeProcessExtension CleverAge\ProcessBundle\Registry\TransformerRegistry: alias: cleverage_process.registry.transformer CleverAge\ProcessBundle\Registry\TransformerRegistryInterface: diff --git a/docs/reference/01-process_definition.md b/docs/reference/01-process_definition.md index a1911a3c..766f06d1 100644 --- a/docs/reference/01-process_definition.md +++ b/docs/reference/01-process_definition.md @@ -47,6 +47,10 @@ Process attributes The process code (key of the `configurations` array) must be unique in the whole application: a process cannot be defined twice, even in different files. +The codes of the processes, of their tasks and of the generic transformers are kept as written, dashes included +(`demo.x-y`). Before 5.7, their dashes were replaced by underscores (`demo.x_y`), but not those of the references to +them: the former name still works, with a deprecation, until v6.0. + **description**: optional string to describe a process. Displayed in process list and help. Should not be too long (~ one line). Default is empty. diff --git a/docs/reference/03-generic_transformers_definition.md b/docs/reference/03-generic_transformers_definition.md index 606fb990..f45bc200 100644 --- a/docs/reference/03-generic_transformers_definition.md +++ b/docs/reference/03-generic_transformers_definition.md @@ -74,4 +74,5 @@ clever_age_process: prefix: product ``` -As any transformer code, generic transformer codes must be unique: use a prefix to avoid conflicts. +As any transformer code, generic transformer codes must be unique: use a prefix to avoid conflicts. A dash is kept in +the code (it was replaced by an underscore before 5.7, the former name is deprecated). diff --git a/src/Configuration/DeprecatedCodeAliases.php b/src/Configuration/DeprecatedCodeAliases.php new file mode 100644 index 00000000..d0fa28d1 --- /dev/null +++ b/src/Configuration/DeprecatedCodeAliases.php @@ -0,0 +1,47 @@ + $codes + * + * @return array former name => code + */ + public static function create(iterable $codes): array + { + $codes = array_map(strval(...), [...$codes]); + $aliases = []; + foreach ($codes as $code) { + if (!str_contains($code, '-') || str_contains($code, '_')) { + continue; + } + $alias = str_replace('-', '_', $code); + // Both were defined: none was renamed + if (!\in_array($alias, $codes, true)) { + $aliases[$alias] = $code; + } + } + + return $aliases; + } +} diff --git a/src/DependencyInjection/CleverAgeProcessExtension.php b/src/DependencyInjection/CleverAgeProcessExtension.php index dd854401..b857accd 100644 --- a/src/DependencyInjection/CleverAgeProcessExtension.php +++ b/src/DependencyInjection/CleverAgeProcessExtension.php @@ -15,6 +15,7 @@ use CleverAge\ProcessBundle\Attribute\AsTask; use CleverAge\ProcessBundle\Attribute\AsTransformer; +use CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases; use CleverAge\ProcessBundle\Configuration\TaskConfiguration; use CleverAge\ProcessBundle\Model\ProcessStopCheckerInterface; use CleverAge\ProcessBundle\Model\TaskInterface; @@ -77,6 +78,13 @@ static function (ChildDefinition $definition, AsTransformer $attribute): void { $processConfigurationRegistry->replaceArgument(1, $config['default_error_strategy']); $processConfigurationRegistry->replaceArgument(2, $config['logs']); + // Former names of the generic transformers whose code has a dash (deprecated, see DeprecatedCodeAliases) + $genericTransformerCodes = array_keys($config['generic_transformers']); + if ([] !== array_filter($genericTransformerCodes, static fn (int|string $code): bool => str_contains((string) $code, '-'))) { + $container->getDefinition('cleverage_process.registry.transformer') + ->replaceArgument(1, DeprecatedCodeAliases::create($genericTransformerCodes)); + } + // Automatic transformer creation from config foreach ($config['generic_transformers'] as $transformerCode => $transformerConfig) { $transformerDefinition = new Definition(GenericTransformer::class); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3793f20d..a933a38b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -81,6 +81,8 @@ protected function appendRootTransformersConfigDefinition(NodeBuilder $definitio { $transformersArrayDefinition = $definition->arrayNode('generic_transformers') ->useAttributeAsKey('code') + // Keep the dashes of the codes (replaced by underscores before 5.7, see DeprecatedCodeAliases) + ->normalizeKeys(false) ->arrayPrototype(); // Process list @@ -120,6 +122,8 @@ protected function appendRootProcessConfigDefinition(NodeBuilder $definition): v { $configurationsArrayDefinition = $definition->arrayNode('configurations') ->useAttributeAsKey('code') + // Keep the dashes of the codes (replaced by underscores before 5.7, see DeprecatedCodeAliases) + ->normalizeKeys(false) ->arrayPrototype(); // Process list @@ -178,6 +182,8 @@ protected function appendProcessConfigDefinition(NodeBuilder $definition): void $tasksArrayDefinition = $definition ->arrayNode('tasks') ->useAttributeAsKey('code') + // Keep the dashes of the codes (replaced by underscores before 5.7, see DeprecatedCodeAliases) + ->normalizeKeys(false) ->arrayPrototype(); // Process list diff --git a/src/Registry/ProcessConfigurationRegistry.php b/src/Registry/ProcessConfigurationRegistry.php index d1d1d4b5..612e08ef 100644 --- a/src/Registry/ProcessConfigurationRegistry.php +++ b/src/Registry/ProcessConfigurationRegistry.php @@ -13,6 +13,7 @@ namespace CleverAge\ProcessBundle\Registry; +use CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases; use CleverAge\ProcessBundle\Configuration\ProcessConfiguration; use CleverAge\ProcessBundle\Configuration\TaskConfiguration; use CleverAge\ProcessBundle\Exception\InvalidProcessConfigurationException; @@ -33,6 +34,11 @@ class ProcessConfigurationRegistry implements ProcessConfigurationRegistryInterf */ protected array $processConfigurations = []; + /** + * @var array|null + */ + private ?array $deprecatedProcessCodes = null; + /** * @param array> $rawConfiguration * @param array{success_level?: string, failed_level?: string} $defaultLogLevels @@ -50,6 +56,7 @@ public function getProcessConfiguration(string $processCode): ProcessConfigurati if (!$this->hasProcessConfiguration($processCode)) { throw MissingProcessException::create($processCode); } + $processCode = $this->resolveDeprecatedProcessCode($processCode); $this->resolveConfiguration($processCode); return $this->processConfigurations[$processCode]; @@ -92,7 +99,103 @@ public function reset(): void public function hasProcessConfiguration(string $processCode): bool { - return \array_key_exists($processCode, $this->rawConfiguration); + return \array_key_exists($processCode, $this->rawConfiguration) + || \array_key_exists($processCode, $this->getDeprecatedProcessCodes()); + } + + /** + * @return array former name of the processes whose code has a dash => code + */ + private function getDeprecatedProcessCodes(): array + { + return $this->deprecatedProcessCodes ??= DeprecatedCodeAliases::create(array_keys($this->rawConfiguration)); + } + + private function resolveDeprecatedProcessCode(string $processCode): string + { + if (\array_key_exists($processCode, $this->rawConfiguration)) { + return $processCode; + } + $code = $this->getDeprecatedProcessCodes()[$processCode]; + // @deprecated since 5.7, the former name will not be found in v6.0 + trigger_deprecation( + 'cleverage/process-bundle', + '5.7', + 'Using the process "%s" by the name "%s", with underscores instead of dashes, is deprecated: use its code "%s". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', + $code, + $processCode, + $code, + ); + + return $code; + } + + /** + * Task references using the former name of a task whose code has a dash (deprecated). + * + * @param array $rawProcessConfiguration + * + * @return array + */ + private function resolveDeprecatedTaskReferences(string $processCode, array $rawProcessConfiguration): array + { + /** @var array $tasks */ + $tasks = $rawProcessConfiguration['tasks']; + // Only when a reference is unknown (an unknown reference is reported by checkTaskReferences()) + $references = [$rawProcessConfiguration['entry_point'] ?? null, $rawProcessConfiguration['end_point'] ?? null]; + foreach ($tasks as $rawTaskConfiguration) { + foreach (['outputs', 'error_outputs', 'errors'] as $key) { + $references = [...$references, ...(\is_array($rawTaskConfiguration[$key] ?? null) ? $rawTaskConfiguration[$key] : [])]; + } + } + $unknownReferences = array_filter( + $references, + static fn (mixed $reference): bool => \is_string($reference) && !\array_key_exists($reference, $tasks) + ); + if ([] === $unknownReferences) { + return $rawProcessConfiguration; + } + $aliases = DeprecatedCodeAliases::create(array_keys($tasks)); + $resolve = static function (string $reference, string $key) use ($aliases, $processCode): string { + if (!\array_key_exists($reference, $aliases)) { + return $reference; + } + // @deprecated since 5.7, the former name will not be found in v6.0 + trigger_deprecation( + 'cleverage/process-bundle', + '5.7', + 'Referencing the task "%s" of the process "%s" by the name "%s" in "%s", with underscores instead of dashes, is deprecated: use its code "%s". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', + $aliases[$reference], + $processCode, + $reference, + $key, + $aliases[$reference], + ); + + return $aliases[$reference]; + }; + foreach (['entry_point', 'end_point'] as $key) { + if (\is_string($rawProcessConfiguration[$key] ?? null)) { + $rawProcessConfiguration[$key] = $resolve($rawProcessConfiguration[$key], $key); + } + } + foreach ($tasks as $taskCode => $rawTaskConfiguration) { + if (!\is_array($rawTaskConfiguration)) { + continue; + } + foreach (['outputs', 'error_outputs', 'errors'] as $key) { + if (\is_array($rawTaskConfiguration[$key] ?? null)) { + $rawTaskConfiguration[$key] = array_map( + static fn (mixed $reference): mixed => \is_string($reference) ? $resolve($reference, $key) : $reference, + $rawTaskConfiguration[$key] + ); + } + } + $tasks[$taskCode] = $rawTaskConfiguration; + } + $rawProcessConfiguration['tasks'] = $tasks; + + return $rawProcessConfiguration; } protected function resolveConfiguration(string $processCode): void @@ -100,7 +203,7 @@ protected function resolveConfiguration(string $processCode): void if (\array_key_exists($processCode, $this->processConfigurations)) { return; } - $rawProcessConfiguration = $this->rawConfiguration[$processCode]; + $rawProcessConfiguration = $this->resolveDeprecatedTaskReferences($processCode, $this->rawConfiguration[$processCode]); /** @var TaskConfiguration[] $taskConfigurations */ $taskConfigurations = []; /** @var array $errorOutputsKeys */ diff --git a/src/Registry/TransformerRegistry.php b/src/Registry/TransformerRegistry.php index a21c974b..221a0680 100644 --- a/src/Registry/TransformerRegistry.php +++ b/src/Registry/TransformerRegistry.php @@ -38,9 +38,12 @@ class TransformerRegistry implements TransformerRegistryInterface /** * @param ServiceProviderInterface|null $locator + * @param array $deprecatedCodes former name of the generic transformers + * whose code has a dash => code (internal) */ public function __construct( protected ?ServiceProviderInterface $locator = null, + private readonly array $deprecatedCodes = [], ) { } @@ -80,6 +83,18 @@ public function getTransformers(): array public function getTransformer(string $code): TransformerInterface { + if (!$this->hasRegisteredTransformer($code) && isset($this->deprecatedCodes[$code])) { + // @deprecated since 5.7, the former name will not be found in v6.0 + trigger_deprecation( + 'cleverage/process-bundle', + '5.7', + 'Using the generic transformer "%s" by the name "%s", with underscores instead of dashes, is deprecated: use its code "%s". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', + $this->deprecatedCodes[$code], + $code, + $this->deprecatedCodes[$code], + ); + $code = $this->deprecatedCodes[$code]; + } if (isset($this->transformers[$code])) { return $this->transformers[$code]; } @@ -101,6 +116,11 @@ public function getTransformer(string $code): TransformerInterface } public function hasTransformer(string $code): bool + { + return $this->hasRegisteredTransformer($code) || isset($this->deprecatedCodes[$code]); + } + + private function hasRegisteredTransformer(string $code): bool { return isset($this->transformers[$code]) || ($this->locator?->has($code) ?? false); } diff --git a/tests/Command/ExecuteProcessCommandTest.php b/tests/Command/ExecuteProcessCommandTest.php index 0b44c0fc..bb8d6bdc 100644 --- a/tests/Command/ExecuteProcessCommandTest.php +++ b/tests/Command/ExecuteProcessCommandTest.php @@ -33,6 +33,7 @@ #[UsesClass(ProcessConfigurationRegistry::class)] #[UsesClass(ConsoleProcessEvent::class)] #[UsesClass(JsonStreamFile::class)] +#[UsesClass(\CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases::class)] class ExecuteProcessCommandTest extends TestCase { private string $outputFile; diff --git a/tests/Command/ListProcessCommandTest.php b/tests/Command/ListProcessCommandTest.php index f8222953..ab2556c7 100644 --- a/tests/Command/ListProcessCommandTest.php +++ b/tests/Command/ListProcessCommandTest.php @@ -28,6 +28,7 @@ #[UsesClass(TaskConfiguration::class)] #[UsesClass(ProcessConfigurationRegistry::class)] #[UsesClass(InvalidProcessConfigurationException::class)] +#[UsesClass(\CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases::class)] class ListProcessCommandTest extends TestCase { public function testThePublicProcessesAreListedSortedByCode(): void diff --git a/tests/Configuration/DeprecatedCodeAliasesTest.php b/tests/Configuration/DeprecatedCodeAliasesTest.php new file mode 100644 index 00000000..ef50a802 --- /dev/null +++ b/tests/Configuration/DeprecatedCodeAliasesTest.php @@ -0,0 +1,34 @@ + 'demo.x-y', 'a_b_c' => 'a-b-c'], + DeprecatedCodeAliases::create(['demo.x-y', 'a-b-c', 'no_dash', 'dash-and_underscore', 'both-defined', 'both_defined', 'plain', 0]) + ); + } +} diff --git a/tests/DependencyInjection/CleverAgeProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeProcessExtensionTest.php index e2255ddb..90ca1497 100644 --- a/tests/DependencyInjection/CleverAgeProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeProcessExtensionTest.php @@ -29,6 +29,7 @@ use CleverAge\ProcessBundle\Task\DummyTask; use CleverAge\ProcessBundle\Tests\Fixtures\AttributedTask; use CleverAge\ProcessBundle\Tests\Fixtures\AttributedTransformer; +use CleverAge\ProcessBundle\Transformer\GenericTransformer; use CleverAge\ProcessBundle\Transformer\String\TrimTransformer; use CleverAge\ProcessBundle\Transformer\TransformerInterface; use PHPUnit\Framework\Attributes\CoversClass; @@ -45,6 +46,7 @@ #[CoversClass(CleverAgeProcessExtension::class)] #[UsesClass(Configuration::class)] +#[UsesClass(\CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases::class)] #[UsesClass(AsTransformer::class)] #[UsesClass(AsTask::class)] class CleverAgeProcessExtensionTest extends TestCase @@ -219,6 +221,24 @@ public function testTheProcessManagerIsResetBetweenExecutions(): void ); } + /** + * The former names of the generic transformers whose code has a dash (dashes replaced by underscores before 5.7) are + * given to the transformer registry, as deprecated aliases. + */ + public function testTheFormerNamesOfTheGenericTransformersAreGivenToTheRegistry(): void + { + $transformer = ['transformers' => ['callback' => ['callback' => 'mb_strtoupper']]]; + $container = new ContainerBuilder(); + (new CleverAgeProcessExtension())->load([], $container); + self::assertSame([], $container->getDefinition('cleverage_process.registry.transformer')->getArgument(1)); + + $container = new ContainerBuilder(); + (new CleverAgeProcessExtension())->load([['generic_transformers' => ['to-upper' => $transformer, 'plain' => $transformer]]], $container); + + self::assertSame(['to_upper' => 'to-upper'], $container->getDefinition('cleverage_process.registry.transformer')->getArgument(1)); + self::assertTrue($container->hasDefinition(GenericTransformer::class.'\\to-upper')); + } + public function testTheDataQueueListenerIsDeprecated(): void { $container = new ContainerBuilder(); diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 2c35894c..3ea69d24 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -210,4 +210,27 @@ private function process(array $config): array { return (new Processor())->processConfiguration(new Configuration(), [$config]); } + + /** + * The dashes of the codes were replaced by underscores (key normalization), not those of the references to them. + */ + public function testTheDashesOfTheCodesAreKept(): void + { + $config = $this->process([ + 'generic_transformers' => ['to-upper' => ['transformers' => ['callback' => ['callback' => 'mb_strtoupper']]]], + 'configurations' => ['demo.x-y' => ['tasks' => [ + 'first-task' => ['task' => 'transformer', 'outputs' => ['next-task']], + 'next-task' => ['task' => 'transformer'], + ]]], + ]); + + self::assertSame(['to-upper'], array_keys($config['generic_transformers'])); + self::assertSame(['demo.x-y'], array_keys($config['configurations'])); + self::assertSame(['first-task', 'next-task'], array_keys($config['configurations']['demo.x-y']['tasks'])); + // The keys of the options are still normalized + self::assertArrayHasKey('error_outputs', $this->process(['configurations' => ['p' => ['tasks' => [ + 't' => ['task' => 'transformer', 'error-outputs' => ['u']], + 'u' => ['task' => 'transformer'], + ]]]])['configurations']['p']['tasks']['t']); + } } diff --git a/tests/Registry/ProcessConfigurationRegistryTest.php b/tests/Registry/ProcessConfigurationRegistryTest.php index 1ab28cdd..c0c7e84f 100644 --- a/tests/Registry/ProcessConfigurationRegistryTest.php +++ b/tests/Registry/ProcessConfigurationRegistryTest.php @@ -27,6 +27,7 @@ #[CoversClass(InvalidProcessConfigurationException::class)] #[UsesClass(ProcessConfiguration::class)] #[UsesClass(TaskConfiguration::class)] +#[UsesClass(\CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases::class)] class ProcessConfigurationRegistryTest extends TestCase { public function testTaskCodeNotResolvedAtCompileTimeThrows(): void @@ -223,4 +224,62 @@ private function rawProcess(array $tasks, array $processConfiguration = []): arr ], $tasks), ]; } + + public function testTheCodesWithDashesAreKept(): void + { + $registry = new ProcessConfigurationRegistry([ + 'demo.x-y' => $this->rawProcess( + ['first-task' => ['outputs' => ['next-task']], 'next-task' => []], + ['entry_point' => 'first-task', 'end_point' => 'next-task'] + ), + ], 'stop'); + + $processConfiguration = $registry->getProcessConfiguration('demo.x-y'); + + self::assertSame('demo.x-y', $processConfiguration->getCode()); + self::assertSame('first-task', $processConfiguration->getEntryPoint()?->getCode()); + self::assertSame(['next-task'], array_map( + static fn (TaskConfiguration $task): string => $task->getCode(), + $processConfiguration->getTaskConfiguration('first-task')->getNextTasksConfigurations() + )); + } + + /** + * The former names (dashes replaced by underscores before 5.7) still work, with a deprecation. + */ + public function testTheFormerNamesAreDeprecated(): void + { + $registry = new ProcessConfigurationRegistry([ + 'demo.x-y' => $this->rawProcess( + ['first-task' => ['outputs' => ['next_task'], 'error_outputs' => ['error-task']], 'next-task' => [], 'error-task' => []], + ['entry_point' => 'first_task'] + ), + ], 'stop'); + + self::assertTrue($registry->hasProcessConfiguration('demo.x_y')); + self::assertFalse($registry->hasProcessConfiguration('demo.x.y')); + $deprecations = []; + set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { + $deprecations[] = $errstr; + + return true; + }, \E_USER_DEPRECATED); + try { + $processConfiguration = $registry->getProcessConfiguration('demo.x_y'); + } finally { + restore_error_handler(); + } + + self::assertSame('demo.x-y', $processConfiguration->getCode()); + self::assertSame('first-task', $processConfiguration->getEntryPoint()?->getCode()); + self::assertSame(['next-task'], array_map( + static fn (TaskConfiguration $task): string => $task->getCode(), + $processConfiguration->getTaskConfiguration('first-task')->getNextTasksConfigurations() + )); + self::assertSame([ + 'Since cleverage/process-bundle 5.7: Using the process "demo.x-y" by the name "demo.x_y", with underscores instead of dashes, is deprecated: use its code "demo.x-y". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', + 'Since cleverage/process-bundle 5.7: Referencing the task "first-task" of the process "demo.x-y" by the name "first_task" in "entry_point", with underscores instead of dashes, is deprecated: use its code "first-task". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', + 'Since cleverage/process-bundle 5.7: Referencing the task "next-task" of the process "demo.x-y" by the name "next_task" in "outputs", with underscores instead of dashes, is deprecated: use its code "next-task". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', + ], $deprecations); + } } diff --git a/tests/Registry/TransformerRegistryTest.php b/tests/Registry/TransformerRegistryTest.php index b8d156c9..3a358a30 100644 --- a/tests/Registry/TransformerRegistryTest.php +++ b/tests/Registry/TransformerRegistryTest.php @@ -17,6 +17,7 @@ use CleverAge\ProcessBundle\Registry\TransformerRegistry; use CleverAge\ProcessBundle\Transformer\CastTransformer; use CleverAge\ProcessBundle\Transformer\String\TrimTransformer; +use CleverAge\ProcessBundle\Transformer\TransformerInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; @@ -135,4 +136,32 @@ private function collectDeprecations(callable $callable): array return $deprecations; } + + /** + * The former name of a generic transformer whose code has a dash (dashes replaced by underscores before 5.7) still + * works, with a deprecation. + */ + public function testTheFormerNamesOfTheGenericTransformersAreDeprecated(): void + { + $transformer = new class implements TransformerInterface { + public function transform(mixed $value, array $options = []): mixed + { + return $value; + } + + public function getCode(): string + { + return 'to-upper'; + } + }; + $registry = new TransformerRegistry(new ServiceLocator(['to-upper' => static fn (): TransformerInterface => $transformer]), ['to_upper' => 'to-upper']); + + self::assertTrue($registry->hasTransformer('to-upper')); + self::assertTrue($registry->hasTransformer('to_upper')); + self::assertSame([], $this->collectDeprecations(static fn () => self::assertSame($transformer, $registry->getTransformer('to-upper')))); + self::assertSame( + ['Since cleverage/process-bundle 5.7: Using the generic transformer "to-upper" by the name "to_upper", with underscores instead of dashes, is deprecated: use its code "to-upper". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.'], + $this->collectDeprecations(static fn () => self::assertSame($transformer, $registry->getTransformer('to_upper'))) + ); + } } diff --git a/tests/Task/Process/ProcessExecutorTaskTest.php b/tests/Task/Process/ProcessExecutorTaskTest.php index 01c02c38..d10ad9ad 100644 --- a/tests/Task/Process/ProcessExecutorTaskTest.php +++ b/tests/Task/Process/ProcessExecutorTaskTest.php @@ -38,6 +38,7 @@ #[\PHPUnit\Framework\Attributes\UsesClass(ProcessHistory::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessState::class)] #[\PHPUnit\Framework\Attributes\UsesClass(ProcessConfigurationRegistry::class)] +#[\PHPUnit\Framework\Attributes\UsesClass(\CleverAge\ProcessBundle\Configuration\DeprecatedCodeAliases::class)] class ProcessExecutorTaskTest extends TestCase { public function testInputIsPassedToTheSubProcessAndItsOutputIsForwarded(): void