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
* [#71](https://github.com/cleverage/rest-process-bundle/issues/71) Configuring a key under `clever_age_rest_process` is deprecated: the bundle has no configuration and the keys were ignored without notice (new internal `Configuration`, empty; notice when the container is compiled). They will be rejected in 4.0. Update documentation, add tests.
* [#69](https://github.com/cleverage/rest-process-bundle/issues/69) The bundle throws exceptions implementing `ProcessExceptionInterface` of the process bundle instead of raw SPL exceptions (as [cleverage/process-bundle#317](https://github.com/cleverage/process-bundle/issues/317)): new `Exception\UnexpectedValueException`, extending the SPL exceptions thrown before (same messages, the existing `catch` keep working). `RestException` (and so `RestRequestException` and `MissingClientException`) implements `ProcessExceptionInterface`; `RequestTask` throws a `RestRequestException` instead of a raw `\Exception` for an invalid response code (same message). Add tests.
* [#67](https://github.com/cleverage/rest-process-bundle/issues/67) Composer: require PHP `^8.2` instead of `>=8.2` (PHP 9 is no longer accepted before being tested), remove the authorization of the `symfony/flex` plugin, which is not required (the CI installs it globally), as [cleverage/process-bundle#319](https://github.com/cleverage/process-bundle/issues/319).
* [#62](https://github.com/cleverage/rest-process-bundle/issues/62) Define the public API (Symfony BC promise, as [cleverage/process-bundle#279](https://github.com/cleverage/process-bundle/issues/279)): `RequestTask`, `ClientRegistry` and `CleverAgeRestProcessBundle` are marked `@final since 3.3`, they will be `final` in 4.0: extending them triggers a deprecation with the Symfony `DebugClassLoader`. `Client` (extended by the applications) and the exceptions stay open. `CleverAgeRestProcessExtension` and `RegisterClientsPass` are marked `@internal`.
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fetch:
url_parameters: { codePostal: '{{ codePostal }}' }
```

No option can be configured under `clever_age_rest_process`: a key there is ignored. Configuring one is deprecated since 3.3 (an `E_USER_DEPRECATED` error is triggered when the container is compiled), the keys will be rejected in 4.0.

## Documentation

- Cookbooks
Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/CleverAgeRestProcessExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ class CleverAgeRestProcessExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$keys = array_keys(array_merge(...$configs));
if ([] !== $keys) {
trigger_deprecation(
'cleverage/rest-process-bundle',
'3.3',
'Configuring "%s" is deprecated, the bundle has no configuration: the keys "%s" are ignored. They will be rejected in 4.0.',
$this->getAlias(),
implode('", "', $keys),
);
}
$this->processConfiguration(new Configuration(), $configs);

$this->findServices($container, __DIR__.'/../../config/services');

$container->registerAttributeForAutoconfiguration(
Expand Down
37 changes: 37 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/RestProcessBundle 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\RestProcessBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* The bundle has no option: the configured keys are ignored with a deprecation (see CleverAgeRestProcessExtension::load()), they will be
* rejected in 4.0.
*
* @internal
*/
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('clever_age_rest_process');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
$rootNode->ignoreExtraKeys();

return $treeBuilder;
}
}
50 changes: 50 additions & 0 deletions tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CleverAge\RestProcessBundle\Attribute\AsRestClient;
use CleverAge\RestProcessBundle\DependencyInjection\CleverAgeRestProcessExtension;
use CleverAge\RestProcessBundle\DependencyInjection\Configuration;
use CleverAge\RestProcessBundle\Registry\ClientRegistry;
use CleverAge\RestProcessBundle\Task\RequestTask;
use CleverAge\RestProcessBundle\Tests\Fixtures\AttributedClient;
Expand All @@ -29,6 +30,7 @@
use Symfony\Component\Yaml\Yaml;

#[CoversClass(CleverAgeRestProcessExtension::class)]
#[CoversClass(Configuration::class)]
#[CoversClass(AsRestClient::class)]
class CleverAgeRestProcessExtensionTest extends TestCase
{
Expand Down Expand Up @@ -110,4 +112,52 @@ public function testAsRestClientAttributeRegistersTheCode(): void

self::assertSame([['code' => 'app_attributed']], $container->getDefinition('app.attributed')->getTag('cleverage.rest.client'));
}

public function testConfigurationKeysAreDeprecated(): void
{
$deprecations = $this->collectDeprecations(static function (): void {
(new CleverAgeRestProcessExtension())->load([[], ['foo' => true], ['bar' => 1, 'foo' => false]], new ContainerBuilder());
});

self::assertSame(['Since cleverage/rest-process-bundle 3.3: Configuring "clever_age_rest_process" is deprecated, the bundle has no configuration: the keys "foo", "bar" are ignored. They will be rejected in 4.0.'], $deprecations);
}

public function testNoDeprecationWithoutConfigurationKey(): void
{
$deprecations = $this->collectDeprecations(static function (): void {
(new CleverAgeRestProcessExtension())->load([[], []], new ContainerBuilder());
});

self::assertSame([], $deprecations);
}

public function testConfigurationHasNoOption(): void
{
$configuration = (new CleverAgeRestProcessExtension())->getConfiguration([], new ContainerBuilder());

self::assertInstanceOf(Configuration::class, $configuration);
self::assertSame('clever_age_rest_process', $configuration->getConfigTreeBuilder()->buildTree()->getName());
}

/**
* @param callable(): void $callback
*
* @return list<string>
*/
private function collectDeprecations(callable $callback): array
{
$deprecations = [];
set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool {
$deprecations[] = $errstr;

return true;
}, \E_USER_DEPRECATED);
try {
$callback();
} finally {
restore_error_handler();
}

return $deprecations;
}
}
Loading