From cd3aaa965aae745f14586be2e7834051b13fe527 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Tue, 1 Dec 2026 17:05:25 +0100 Subject: [PATCH] #111 - Rename the root of the configuration to cleverage_process Co-Authored-By: Claude Opus 5.5 --- .github/ISSUE_TEMPLATE/bug.md | 2 +- CHANGELOG.md | 1 + UPGRADE.md | 18 +++++++ docs/01-quick_start.md | 23 ++++---- docs/04-advanced_workflow.md | 4 +- docs/06-testing.md | 4 +- docs/cookbooks/01-common_setup.md | 6 +-- docs/cookbooks/etl_aggregate_reports.md | 2 +- docs/cookbooks/etl_file_sync.md | 2 +- docs/reference/01-process_definition.md | 2 +- .../03-generic_transformers_definition.md | 4 +- .../transformers/generic_transformer.md | 10 ++-- src/CleverAgeProcessBundle.php | 15 ++++++ .../CleverAgeProcessExtension.php | 6 +++ src/DependencyInjection/Configuration.php | 2 +- tests/App/TestKernel.php | 2 +- tests/CleverAgeProcessBundleTest.php | 52 +++++++++++++++++++ .../DependencyInjection/ConfigurationTest.php | 16 ++++-- tests/Functional/KernelTest.php | 11 ++++ 19 files changed, 147 insertions(+), 35 deletions(-) create mode 100644 tests/CleverAgeProcessBundleTest.php diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 3ce4fcfb..cb33f4d4 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -15,7 +15,7 @@ assignees: '' ```yaml -clever_age_process: +cleverage_process: configurations: demo.: tasks: diff --git a/CHANGELOG.md b/CHANGELOG.md index cb223096..23d33353 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Latest * [#143](https://github.com/cleverage/process-bundle/issues/143) Narrow native types that were never `null` in practice: `AbstractConfigurableTask::getOptions()` and `ProcessState::getContextualizedOptions()` return `array` (instead of `?array`), `CsvResource::$lineNumber` is an `int` and `ProcessHistory::$startDate` a `\DateTimeInterface` (instead of nullable types). Overrides must declare the narrowed types (see `UPGRADE.md`). Improve PHPStan level from 7 to 8. * [#234](https://github.com/cleverage/process-bundle/issues/234) ArrayFirstTransformer: restore the meaning of the `allow_not_iterable` option, inverted since v4.0. By default (`false`), a non-iterable input now throws an `UnexpectedValueException` (it was returned unchanged); with `allow_not_iterable: true`, it is returned unchanged (a scalar or `null` threw a `TypeError`, an object returned its first property). Set `allow_not_iterable: true` to keep the former default behaviour (see `UPGRADE.md`). An iterable object (`\Traversable`) returns its first element (`false` or its first property before), a generator already run throws an `UnexpectedValueException`. Update documentation, add tests. * [#507](https://github.com/cleverage/process-bundle/issues/507) `csv_reader`, `input_csv_reader`: a line that cannot be read (number of columns not matching the headers, line that cannot be parsed) sends `['csv_file' => , 'csv_line' => , 'csv_values' => ]` to the error output, instead of the input of the task (`null`, or the file path for `input_csv_reader`, see `UPGRADE.md`), and `csv_file` / `csv_line` are in the error context of the logged error. `CsvResource::readLine()` throws an `InvalidCsvLineException` (an `UnexpectedValueException`) carrying the values read. Update documentation, add tests. +* [#111](https://github.com/cleverage/process-bundle/issues/111) The root of the configuration is renamed from `clever_age_process` to `cleverage_process` (alias of the extension), the former one is no longer recognized (see `UPGRADE.md`). Update documentation, add 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 ec061b94..d2b1220b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,24 @@ Upgrade Guide PHP 8.2 and Symfony 6.4 are no longer supported: upgrade to PHP 8.3 or later and to Symfony 7.4 or 8.x before installing v6.0 (Composer keeps the bundle on v5 otherwise). +### Root of the configuration + +The root key of the configuration is renamed from `clever_age_process` to `cleverage_process`, like the other +`cleverage_*` names of the bundle. The former key is no longer recognized: `cache:clear` fails with +`There is no extension able to load the configuration for "clever_age_process" (in "")…`. Find every use of the +former key (YAML files, including the processes of `config/packages/process/` and the `when@` sections, PHP and +XML configuration, kernel): + +```bash +grep -rn 'clever_age_process' config/ src/ +``` + +and rename it to `cleverage_process`: the YAML key (`cleverage_process:`), +`$container->extension('cleverage_process', [...])` in a PHP configuration, whose generated config builder is +`Symfony\Config\CleverageProcessConfig` (instead of `CleverAgeProcessConfig`). The name of the file created by the +Flex recipe (`config/packages/clever_age_process.yaml`) is free, you can rename it `cleverage_process.yaml`. +`config:dump-reference cleverage_process` gives the reference of the configuration. + ### Typed class constants The class constants of the bundle are typed. A class extending a class of the bundle and redeclaring one of its diff --git a/docs/01-quick_start.md b/docs/01-quick_start.md index a637ac5b..a01f1366 100644 --- a/docs/01-quick_start.md +++ b/docs/01-quick_start.md @@ -32,7 +32,7 @@ composer require cleverage/process-bundle With [Symfony Flex](https://symfony.com/doc/current/setup/flex.html), the [recipe](https://github.com/symfony/recipes-contrib/tree/main/cleverage/process-bundle) registers the bundle and creates: -- `config/packages/clever_age_process.yaml`: the [global configuration](#global-configuration), which imports the +- `config/packages/cleverage_process.yaml`: the [global configuration](#global-configuration), which imports the `config/packages/process/` directory, - `config/packages/process/`: the directory of your processes, one file per process (see [process definition](reference/01-process_definition.md)). @@ -52,14 +52,15 @@ Without Flex, add the following line to `config/bundles.php`: CleverAge\ProcessBundle\CleverAgeProcessBundle::class => ['all' => true], ``` -Then create the `config/packages/process/` directory and the configuration that imports it: +Then create the `config/packages/process/` directory and the configuration that imports it (the name of the file is +free, only the `cleverage_process` root key matters): ```yaml -# config/packages/clever_age_process.yaml +# config/packages/cleverage_process.yaml imports: - { resource: process/ } -clever_age_process: +cleverage_process: default_error_strategy: stop ``` @@ -96,7 +97,7 @@ these tasks or transformers fails with an explicit message giving the package or ## Global configuration -You can use `./bin/console config:dump-reference clever_age_process` to have a summary of current configuration. +You can use `./bin/console config:dump-reference cleverage_process` to have a summary of current configuration. The configuration has four root keys: - `configurations`: your processes (see [process definition](reference/01-process_definition.md)) @@ -110,8 +111,8 @@ The configuration has four root keys: We recommend keeping the `stop` default, and then specify task by task which one can be skipped: ```yaml -# config/packages/clever_age_process.yaml -clever_age_process: +# config/packages/cleverage_process.yaml +cleverage_process: default_error_strategy: stop ``` @@ -153,10 +154,10 @@ its definitions. The `monolog.logger` tags bind injected loggers to the bundle c Most of the work is done through the bundle configuration. -Under `clever_age_process.configurations` you can add processes, and for each process define a set of `tasks`. +Under `cleverage_process.configurations` you can add processes, and for each process define a set of `tasks`. The most basic configuration for a process is: ```yaml -clever_age_process: +cleverage_process: configurations: : tasks: [] @@ -185,12 +186,12 @@ purpose!) The debug task only dumps its input if the Symfony VarDumper component is installed (otherwise it silently does nothing): `composer require --dev symfony/var-dumper`. -Put this configuration in any file loaded by Symfony, e.g. `config/packages/clever_age_process.yaml`, or one file per +Put this configuration in any file loaded by Symfony, e.g. `config/packages/cleverage_process.yaml`, or one file per process in a `config/packages/process/` folder imported with `imports: [{ resource: process/ }]` (see [common setup](cookbooks/01-common_setup.md#configuration)). ```yaml -clever_age_process: +cleverage_process: configurations: project_prefix.process_name: tasks: diff --git a/docs/04-advanced_workflow.md b/docs/04-advanced_workflow.md index a090008a..34169bff 100644 --- a/docs/04-advanced_workflow.md +++ b/docs/04-advanced_workflow.md @@ -79,7 +79,7 @@ reader is iterable, the transformer is executed once for each line, and the writ outputs the file path only once, at the end, to the `log` task. ```yaml -clever_age_process: +cleverage_process: configurations: app.csv_copy: tasks: @@ -179,7 +179,7 @@ values are not inherited: pass them explicitly with the `context` option (placeh forward the parent context). ```yaml -clever_age_process: +cleverage_process: configurations: app.import_all: tasks: diff --git a/docs/06-testing.md b/docs/06-testing.md index ee467b3f..3b926b91 100644 --- a/docs/06-testing.md +++ b/docs/06-testing.md @@ -125,8 +125,8 @@ the process fails as soon as it starts. Its `logs.store_in_database: false` opti logs, not of the executions. ```yaml -# config/packages/test/clever_age_process.yaml -clever_age_process: +# config/packages/test/cleverage_process.yaml +cleverage_process: configurations: test.app.vat: entry_point: transform diff --git a/docs/cookbooks/01-common_setup.md b/docs/cookbooks/01-common_setup.md index afa29816..de3d1602 100644 --- a/docs/cookbooks/01-common_setup.md +++ b/docs/cookbooks/01-common_setup.md @@ -61,11 +61,11 @@ Configuration Processes are usually defined in a `config/packages/process/` subfolder, imported from the bundle configuration file: ```yaml -# config/packages/clever_age_process.yaml +# config/packages/cleverage_process.yaml imports: - { resource: process/ } -clever_age_process: +cleverage_process: default_error_strategy: stop ``` @@ -108,7 +108,7 @@ Here is a minimal CSV-to-CSV workflow built only with tasks shipped with the bun ```yaml # config/packages/process/app/file_import.yaml -clever_age_process: +cleverage_process: configurations: app.file_import: description: 'Prepare the products CSV file' diff --git a/docs/cookbooks/etl_aggregate_reports.md b/docs/cookbooks/etl_aggregate_reports.md index 0e3c9309..d5ec43ae 100644 --- a/docs/cookbooks/etl_aggregate_reports.md +++ b/docs/cookbooks/etl_aggregate_reports.md @@ -11,7 +11,7 @@ Each line of the log files looks like: ``` ```yaml -clever_age_process: +cleverage_process: configurations: app.etl_report_aggregate: description: 'Aggregate API logs per service' diff --git a/docs/cookbooks/etl_file_sync.md b/docs/cookbooks/etl_file_sync.md index fb4518ef..1f09f15f 100644 --- a/docs/cookbooks/etl_file_sync.md +++ b/docs/cookbooks/etl_file_sync.md @@ -5,7 +5,7 @@ This recipe describes a typical ETL flow: read a CSV file, reject invalid lines, then write the result to another CSV file while logging some statistics. ```yaml -clever_age_process: +cleverage_process: configurations: app.etl_file_sync: description: 'Normalize the catalog CSV file' diff --git a/docs/reference/01-process_definition.md b/docs/reference/01-process_definition.md index 0fc4468b..2f61a60f 100644 --- a/docs/reference/01-process_definition.md +++ b/docs/reference/01-process_definition.md @@ -5,7 +5,7 @@ YAML Configuration ------------------ ```yaml -clever_age_process: +cleverage_process: default_error_strategy: logs: success_level: diff --git a/docs/reference/03-generic_transformers_definition.md b/docs/reference/03-generic_transformers_definition.md index 20c67304..b3b1d9fb 100644 --- a/docs/reference/03-generic_transformers_definition.md +++ b/docs/reference/03-generic_transformers_definition.md @@ -9,7 +9,7 @@ YAML Configuration ------------------ ```yaml -clever_age_process: +cleverage_process: generic_transformers: : contextual_options: @@ -46,7 +46,7 @@ Example ------- ```yaml -clever_age_process: +cleverage_process: generic_transformers: app_slug_prefix: contextual_options: diff --git a/docs/reference/transformers/generic_transformer.md b/docs/reference/transformers/generic_transformer.md index c7b9a0a7..ebec85af 100644 --- a/docs/reference/transformers/generic_transformer.md +++ b/docs/reference/transformers/generic_transformer.md @@ -1,7 +1,7 @@ GenericTransformer ================== -Class behind the transformers declared in the `clever_age_process.generic_transformers` configuration (see +Class behind the transformers declared in the `cleverage_process.generic_transformers` configuration (see [Generic transformers definition](../03-generic_transformers_definition.md)). It is not a service by itself: one instance is created per declared generic transformer, and it simply applies a preconfigured chain of transformers, optionally parametrized by `contextual_options`. @@ -22,7 +22,7 @@ Transformer reference --------------------- * **Service**: `CleverAge\ProcessBundle\Transformer\GenericTransformer\` (one service per generic transformer) -* **Transformer code**: ``: the key used under `clever_age_process.generic_transformers` +* **Transformer code**: ``: the key used under `cleverage_process.generic_transformers` Accepted inputs --------------- @@ -37,7 +37,7 @@ Possible outputs Options ------- -The definition (`clever_age_process.generic_transformers.`) accepts: +The definition (`cleverage_process.generic_transformers.`) accepts: | Code | Type | Required | Default | Description | |----------------------|---------|:--------:|---------|-------------------------------------------------------------------------------------------------------------------------| @@ -62,7 +62,7 @@ Examples ```yaml # Bundle configuration level (config/packages/*.yaml) -clever_age_process: +cleverage_process: generic_transformers: uppercase: transformers: @@ -79,7 +79,7 @@ uppercase: ~ ```yaml # Bundle configuration level (config/packages/*.yaml) -clever_age_process: +cleverage_process: generic_transformers: substr: contextual_options: diff --git a/src/CleverAgeProcessBundle.php b/src/CleverAgeProcessBundle.php index 81af58b1..31d6099a 100644 --- a/src/CleverAgeProcessBundle.php +++ b/src/CleverAgeProcessBundle.php @@ -13,12 +13,14 @@ namespace CleverAge\ProcessBundle; +use CleverAge\ProcessBundle\DependencyInjection\CleverAgeProcessExtension; use CleverAge\ProcessBundle\DependencyInjection\Compiler\PublicTaskDeprecationCompilerPass; use CleverAge\ProcessBundle\DependencyInjection\Compiler\TaskLocatorCompilerPass; use CleverAge\ProcessBundle\DependencyInjection\Compiler\TransformerLocatorCompilerPass; use CleverAge\ProcessBundle\DependencyInjection\Compiler\UnavailableServicesCompilerPass; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @@ -40,6 +42,19 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new PublicTaskDeprecationCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 110); } + /** + * The alias of the extension, "cleverage_process", is not the one guessed from the bundle name. + */ + #[\Override] + public function getContainerExtension(): ExtensionInterface + { + if (!$this->extension instanceof ExtensionInterface) { + $this->extension = new CleverAgeProcessExtension(); + } + + return $this->extension; + } + #[\Override] public function getPath(): string { diff --git a/src/DependencyInjection/CleverAgeProcessExtension.php b/src/DependencyInjection/CleverAgeProcessExtension.php index f4bcfdb5..896dbca8 100644 --- a/src/DependencyInjection/CleverAgeProcessExtension.php +++ b/src/DependencyInjection/CleverAgeProcessExtension.php @@ -38,6 +38,12 @@ */ class CleverAgeProcessExtension extends Extension { + #[\Override] + public function getAlias(): string + { + return 'cleverage_process'; + } + public function load(array $configs, ContainerBuilder $container): void { // Get the path of the service folder wherever the bundle is installed diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index dd7c577d..df9725eb 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -41,7 +41,7 @@ class Configuration implements ConfigurationInterface ]; public function __construct( - protected string $root = 'clever_age_process', + protected string $root = 'cleverage_process', ) { } diff --git a/tests/App/TestKernel.php b/tests/App/TestKernel.php index 4853c320..dabd9c6e 100644 --- a/tests/App/TestKernel.php +++ b/tests/App/TestKernel.php @@ -108,7 +108,7 @@ protected function configureContainer(ContainerConfigurator $container): void ], ]; } - $container->extension('clever_age_process', [ + $container->extension('cleverage_process', [ 'configurations' => $flushableEndPoints + [ 'test.every_task' => ['tasks' => $tasks], 'test.run' => [ diff --git a/tests/CleverAgeProcessBundleTest.php b/tests/CleverAgeProcessBundleTest.php new file mode 100644 index 00000000..78c382ae --- /dev/null +++ b/tests/CleverAgeProcessBundleTest.php @@ -0,0 +1,52 @@ +getContainerExtension(); + + self::assertInstanceOf(CleverAgeProcessExtension::class, $extension); + self::assertSame('cleverage_process', $extension->getAlias()); + // Built once + self::assertSame($extension, $bundle->getContainerExtension()); + } + + /** + * The former root of the configuration is no longer recognized (renamed in v6.0). + */ + public function testFormerAliasIsNotRegistered(): void + { + $container = new ContainerBuilder(); + $container->registerExtension((new CleverAgeProcessBundle())->getContainerExtension()); + + self::assertTrue($container->hasExtension('cleverage_process')); + self::assertFalse($container->hasExtension('clever_age_process')); + $this->expectException(LogicException::class); + $container->loadFromExtension('clever_age_process', []); + } +} diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index c4ca30c3..ef7b5ad4 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -29,6 +29,14 @@ class ConfigurationTest extends TestCase { use IgnoreDeprecationsTrait; + public function testRootIsTheAliasOfTheExtension(): void + { + $tree = (new Configuration())->getConfigTreeBuilder()->buildTree(); + + self::assertSame('cleverage_process', $tree->getName()); + self::assertSame((new CleverAgeProcessExtension())->getAlias(), $tree->getName()); + } + public function testLogLevelsDefaults(): void { $config = $this->process(['configurations' => ['test.process' => ['tasks' => []]]]); @@ -90,7 +98,7 @@ public function testServiceIsDeprecated(): void } self::assertSame( - ['Since cleverage/process-bundle 5.4: The "service" option of the task "clever_age_process.configurations.test.process.tasks.by_service" is deprecated, reference the task by its code instead ("task: ", given on the reference page of each task; give a code to your own tasks with #[AsTask] or a "cleverage.task" tag). It will be removed in v6.0.'], + ['Since cleverage/process-bundle 5.4: The "service" option of the task "cleverage_process.configurations.test.process.tasks.by_service" is deprecated, reference the task by its code instead ("task: ", given on the reference page of each task; give a code to your own tasks with #[AsTask] or a "cleverage.task" tag). It will be removed in v6.0.'], $deprecations ); } @@ -114,7 +122,7 @@ public function testErrorsIsDeprecated(): void } self::assertSame( - ['Since cleverage/process-bundle 5.4: The "errors" option of the task "clever_age_process.configurations.test.process.tasks.with_errors" is deprecated, use "error_outputs" instead. It will be removed in v6.0.'], + ['Since cleverage/process-bundle 5.4: The "errors" option of the task "cleverage_process.configurations.test.process.tasks.with_errors" is deprecated, use "error_outputs" instead. It will be removed in v6.0.'], $deprecations ); self::assertSame(['error'], $config['configurations']['test.process']['tasks']['with_errors']['errors']); @@ -256,7 +264,7 @@ public function testExclusive(): void self::assertTrue($config['configurations']['test.exclusive']['exclusive']); $this->expectException(InvalidConfigurationException::class); - $this->expectExceptionMessage('Invalid type for path "clever_age_process.configurations.test.process.exclusive". Expected "bool"'); + $this->expectExceptionMessage('Invalid type for path "cleverage_process.configurations.test.process.exclusive". Expected "bool"'); $this->process(['configurations' => ['test.process' => ['exclusive' => 'yes', 'tasks' => []]]]); } @@ -279,7 +287,7 @@ public function testATaskGivenAsAListIsReported(): void public function testPublicMustBeABoolean(): void { $this->expectException(InvalidConfigurationException::class); - $this->expectExceptionMessage('Invalid type for path "clever_age_process.configurations.test.process.public". Expected "bool", but got "string".'); + $this->expectExceptionMessage('Invalid type for path "cleverage_process.configurations.test.process.public". Expected "bool", but got "string".'); $this->process(['configurations' => ['test.process' => ['public' => 'no', 'tasks' => []]]]); } diff --git a/tests/Functional/KernelTest.php b/tests/Functional/KernelTest.php index 9c8a96f7..f9d141ee 100644 --- a/tests/Functional/KernelTest.php +++ b/tests/Functional/KernelTest.php @@ -22,7 +22,9 @@ use CleverAge\ProcessBundle\Transformer\TransformerInterface; use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\Attributes\DataProvider; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\Console\Tester\CommandTester; /** * The bundle in an application (see TestKernel): the container compiles, the tasks and transformers are resolved with @@ -109,6 +111,15 @@ public function testFlushableEndPoint(string $name, mixed $expected): void self::assertSame($expected, $processManager->execute('test.flushable_end_point.'.$name)); } + public function testConfigurationReferenceIsDumpedUnderItsRoot(): void + { + $command = (new Application(self::bootKernel()))->find('config:dump-reference'); + $tester = new CommandTester($command); + + self::assertSame(0, $tester->execute(['name' => 'cleverage_process'])); + self::assertStringStartsWith("# Default configuration for extension with alias: \"cleverage_process\"\ncleverage_process:\n", $tester->getDisplay()); + } + protected static function getKernelClass(): string { return TestKernel::class;