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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ assignees: ''
<!-- A minimal process configuration reproducing the bug, ideally a demo.* process from https://github.com/cleverage/process-bundle-demo -->

```yaml
clever_age_process:
cleverage_process:
configurations:
demo.<name>:
tasks:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => <path>, 'csv_line' => <line number>, 'csv_values' => <values read>]` 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.
Expand Down
18 changes: 18 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<file>")…`. Find every use of the
former key (YAML files, including the processes of `config/packages/process/` and the `when@<env>` 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
Expand Down
23 changes: 12 additions & 11 deletions docs/01-quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand All @@ -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
```

Expand Down Expand Up @@ -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))
Expand All @@ -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
```

Expand Down Expand Up @@ -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:
<process_name>:
tasks: []
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions docs/04-advanced_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions docs/06-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/cookbooks/01-common_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/etl_aggregate_reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/etl_file_sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/01-process_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ YAML Configuration
------------------

```yaml
clever_age_process:
cleverage_process:
default_error_strategy: <stop|skip>
logs:
success_level: <emergency|alert|critical|error|warning|notice|info|debug>
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/03-generic_transformers_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ YAML Configuration
------------------

```yaml
clever_age_process:
cleverage_process:
generic_transformers:
<transformer_code>:
contextual_options:
Expand Down Expand Up @@ -46,7 +46,7 @@ Example
-------

```yaml
clever_age_process:
cleverage_process:
generic_transformers:
app_slug_prefix:
contextual_options:
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/transformers/generic_transformer.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -22,7 +22,7 @@ Transformer reference
---------------------

* **Service**: `CleverAge\ProcessBundle\Transformer\GenericTransformer\<code>` (one service per generic transformer)
* **Transformer code**: `<code>`: the key used under `clever_age_process.generic_transformers`
* **Transformer code**: `<code>`: the key used under `cleverage_process.generic_transformers`

Accepted inputs
---------------
Expand All @@ -37,7 +37,7 @@ Possible outputs
Options
-------

The definition (`clever_age_process.generic_transformers.<code>`) accepts:
The definition (`cleverage_process.generic_transformers.<code>`) accepts:

| Code | Type | Required | Default | Description |
|----------------------|---------|:--------:|---------|-------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -62,7 +62,7 @@ Examples

```yaml
# Bundle configuration level (config/packages/*.yaml)
clever_age_process:
cleverage_process:
generic_transformers:
uppercase:
transformers:
Expand All @@ -79,7 +79,7 @@ uppercase: ~

```yaml
# Bundle configuration level (config/packages/*.yaml)
clever_age_process:
cleverage_process:
generic_transformers:
substr:
contextual_options:
Expand Down
15 changes: 15 additions & 0 deletions src/CleverAgeProcessBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
{
Expand Down
6 changes: 6 additions & 0 deletions src/DependencyInjection/CleverAgeProcessExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Configuration implements ConfigurationInterface
];

public function __construct(
protected string $root = 'clever_age_process',
protected string $root = 'cleverage_process',
) {
}

Expand Down
2 changes: 1 addition & 1 deletion tests/App/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
52 changes: 52 additions & 0 deletions tests/CleverAgeProcessBundleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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;

use CleverAge\ProcessBundle\CleverAgeProcessBundle;
use CleverAge\ProcessBundle\DependencyInjection\CleverAgeProcessExtension;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;

#[CoversClass(CleverAgeProcessBundle::class)]
#[UsesClass(CleverAgeProcessExtension::class)]
class CleverAgeProcessBundleTest extends TestCase
{
public function testExtensionAlias(): void
{
$bundle = new CleverAgeProcessBundle();
$extension = $bundle->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', []);
}
}
Loading