From e8af25626dc09b100d6f93264ec2a6b886c0fc6c Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Mon, 19 Oct 2026 11:48:10 +0200 Subject: [PATCH] #37 - Load the service definitions with a glob pattern instead of a Finder - CleverAgeArchiveProcessExtension::findServices() imports the service definition files with a glob pattern ($loader->import('*.yaml', 'glob')) instead of a Finder and one load() call per file, as cleverage/process-bundle#271. Same signature, same files. - symfony/finder is no longer required (only used there). - Test that every service of config/services/*.yaml is registered. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + composer.json | 1 - .../CleverAgeArchiveProcessExtension.php | 10 ++---- .../CleverAgeArchiveProcessExtensionTest.php | 34 +++++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf1ea51..07d5b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ### Changes +* [#37](https://github.com/cleverage/archive-process-bundle/issues/37) `CleverAgeArchiveProcessExtension::findServices()` loads the service definition files with a glob pattern instead of a `Finder` (same files, as [cleverage/process-bundle#271](https://github.com/cleverage/process-bundle/issues/271)), `symfony/finder` is no longer required. Add tests. * [#35](https://github.com/cleverage/archive-process-bundle/issues/35) Require `symfony/polyfill-php83`, `symfony/polyfill-php84` and `symfony/polyfill-php85` ([cleverage/process-bundle#299](https://github.com/cleverage/process-bundle/issues/299)): the functions of PHP 8.3 to 8.5 can be used while supporting PHP 8.2. Rector targets PHP 8.2 (`withPhpVersion()`, `withPhpSets()` read from `composer.json`) and applies the rules using a newer function when its polyfill is required (no change in the current code). * [#31](https://github.com/cleverage/archive-process-bundle/issues/31) Give a code to the tasks ([cleverage/process-bundle#91](https://github.com/cleverage/process-bundle/issues/91)): `archive_zip` and `archive_unzip` (`task: archive_zip`, with `cleverage/process-bundle` 5.4 or later, referencing them by `service` being deprecated there). The tasks have their class name as service id; fetching them directly from the service container is deprecated (`container.private`), they will be private in 3.0. The former ids `cleverage_archive_process.task.zip` / `cleverage_archive_process.task.unzip` are deprecated aliases, removed in 3.0. Update documentation, add tests. * [#29](https://github.com/cleverage/archive-process-bundle/issues/29) CI: test the lowest versions allowed by `composer.json` (`--prefer-lowest`, PHP 8.2). diff --git a/composer.json b/composer.json index 42404c6..7c67b85 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,6 @@ "cleverage/process-bundle": "^5.0", "symfony/config": "^6.4|^7.4|^8", "symfony/dependency-injection": "^6.4|^7.4|^8", - "symfony/finder": "^6.4|^7.4|^8", "symfony/http-kernel": "^6.4|^7.4|^8", "symfony/options-resolver": "^6.4|^7.4|^8", "symfony/polyfill-php83": "^1.33", diff --git a/src/DependencyInjection/CleverAgeArchiveProcessExtension.php b/src/DependencyInjection/CleverAgeArchiveProcessExtension.php index 8e9ff11..ff26aae 100644 --- a/src/DependencyInjection/CleverAgeArchiveProcessExtension.php +++ b/src/DependencyInjection/CleverAgeArchiveProcessExtension.php @@ -17,7 +17,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Finder\Finder; class CleverAgeArchiveProcessExtension extends Extension { @@ -27,16 +26,11 @@ public function load(array $configs, ContainerBuilder $container): void } /** - * Recursively import config files into container. + * Import the service definition files of a directory into the container. */ protected function findServices(ContainerBuilder $container, string $path, string $extension = 'yaml'): void { - $finder = new Finder(); - $finder->in($path) - ->name('*.'.$extension)->files(); $loader = new YamlFileLoader($container, new FileLocator($path)); - foreach ($finder as $file) { - $loader->load($file->getFilename()); - } + $loader->import('*.'.$extension, 'glob'); } } diff --git a/tests/DependencyInjection/CleverAgeArchiveProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeArchiveProcessExtensionTest.php index a79e49d..30f8918 100644 --- a/tests/DependencyInjection/CleverAgeArchiveProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeArchiveProcessExtensionTest.php @@ -20,10 +20,44 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Yaml\Yaml; #[CoversClass(CleverAgeArchiveProcessExtension::class)] class CleverAgeArchiveProcessExtensionTest extends TestCase { + public function testEveryServiceDefinitionFileIsLoaded(): void + { + $container = new ContainerBuilder(); + (new CleverAgeArchiveProcessExtension())->load([], $container); + + $files = glob(\dirname(__DIR__, 2).'/config/services/*.yaml'); + self::assertIsArray($files); + self::assertNotEmpty($files); + foreach ($files as $file) { + $config = Yaml::parseFile($file, Yaml::PARSE_CUSTOM_TAGS); + self::assertIsArray($config); + if (!isset($config['services'])) { + continue; + } + self::assertIsArray($config['services']); + foreach (array_keys($config['services']) as $id) { + if ('_defaults' === $id) { + continue; + } + if (str_ends_with((string) $id, '\\')) { + // Resource: at least one service registered under the namespace prefix + $registered = array_filter( + array_keys($container->getDefinitions()), + static fn (string $definitionId): bool => str_starts_with($definitionId, (string) $id) + ); + self::assertNotEmpty($registered, \sprintf('No service registered for the "%s" resource of %s', $id, basename($file))); + continue; + } + self::assertTrue($container->has((string) $id), \sprintf('Service "%s" of %s is not registered', $id, basename($file))); + } + } + } + /** * @return iterable */