diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c1441..d37e050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/docs/index.md b/docs/index.md index 5503118..511f89d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/src/DependencyInjection/CleverAgeRestProcessExtension.php b/src/DependencyInjection/CleverAgeRestProcessExtension.php index 96535c1..f0b9596 100644 --- a/src/DependencyInjection/CleverAgeRestProcessExtension.php +++ b/src/DependencyInjection/CleverAgeRestProcessExtension.php @@ -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( diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php new file mode 100644 index 0000000..8471a99 --- /dev/null +++ b/src/DependencyInjection/Configuration.php @@ -0,0 +1,37 @@ +getRootNode(); + $rootNode->ignoreExtraKeys(); + + return $treeBuilder; + } +} diff --git a/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php index 72d5098..d777824 100644 --- a/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php @@ -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; @@ -29,6 +30,7 @@ use Symfony\Component\Yaml\Yaml; #[CoversClass(CleverAgeRestProcessExtension::class)] +#[CoversClass(Configuration::class)] #[CoversClass(AsRestClient::class)] class CleverAgeRestProcessExtensionTest extends TestCase { @@ -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 + */ + 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; + } }