diff --git a/CHANGELOG.md b/CHANGELOG.md index ae95c36d..b8424e24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ## Changes +* [#271](https://github.com/cleverage/process-bundle/issues/271) DependencyInjection: `CleverAgeProcessExtension::findServices()` loads the service definition files with a glob pattern instead of a `Finder` (same files), `Configuration` uses `arrayPrototype()` / `variablePrototype()` / `scalarPrototype()` instead of `prototype()` (same configuration tree). Add tests. * [#282](https://github.com/cleverage/process-bundle/issues/282) Require `psr/container` (`ProcessHelpCommand`), `ext-xmlreader` (`XmlStreamReaderTask`) and `ext-libxml` (`XmlFile`, `XmlStreamReaderTask`, `XpathEvaluatorTransformer`), used directly; add `symfony/cache` (used by the tests) to the dev requirements. * [#268](https://github.com/cleverage/process-bundle/issues/268) Clean up composer.json: remove the unused `symfony/dotenv`, `symfony/runtime` and `symfony/error-handler` dependencies (applications relying on the bundle to install them must require them), bound `symfony/service-contracts` to `^2.5|^3`, update the package description. diff --git a/src/DependencyInjection/CleverAgeProcessExtension.php b/src/DependencyInjection/CleverAgeProcessExtension.php index 5283ce8c..9ed62114 100644 --- a/src/DependencyInjection/CleverAgeProcessExtension.php +++ b/src/DependencyInjection/CleverAgeProcessExtension.php @@ -21,7 +21,6 @@ use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Finder\Finder; /** * This is the class that loads and manages your bundle configuration. @@ -63,16 +62,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/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 0f5a7c63..f347ff63 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,7 +15,6 @@ use CleverAge\ProcessBundle\Configuration\TaskConfiguration; use Psr\Log\LogLevel; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\NodeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -23,7 +22,7 @@ /** * This is the class that validates and merges configuration from your app/config files. * - * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html} + * @see https://symfony.com/doc/current/bundles/configuration.html */ class Configuration implements ConfigurationInterface { @@ -77,10 +76,9 @@ public function getConfigTreeBuilder(): TreeBuilder */ protected function appendRootTransformersConfigDefinition(NodeBuilder $definition): void { - /** @var ArrayNodeDefinition $transformersArrayDefinition */ $transformersArrayDefinition = $definition->arrayNode('generic_transformers') ->useAttributeAsKey('code') - ->prototype('array'); + ->arrayPrototype(); // Process list $transformerListDefinition = $transformersArrayDefinition @@ -99,11 +97,11 @@ protected function appendTransformerConfigDefinition(NodeBuilder $definition): v { $definition ->arrayNode('contextual_options') - ->prototype('variable') + ->variablePrototype() ->end() ->end() ->arrayNode('transformers') - ->prototype('variable') + ->variablePrototype() ->end() ->end(); } @@ -113,10 +111,9 @@ protected function appendTransformerConfigDefinition(NodeBuilder $definition): v */ protected function appendRootProcessConfigDefinition(NodeBuilder $definition): void { - /** @var ArrayNodeDefinition $configurationsArrayDefinition */ $configurationsArrayDefinition = $definition->arrayNode('configurations') ->useAttributeAsKey('code') - ->prototype('array'); + ->arrayPrototype(); // Process list $processListDefinition = $configurationsArrayDefinition @@ -147,7 +144,7 @@ protected function appendProcessConfigDefinition(NodeBuilder $definition): void ->defaultTrue() ->end() ->arrayNode('options') - ->prototype('variable') + ->variablePrototype() ->end() ->end() ->arrayNode('logs') @@ -165,11 +162,10 @@ protected function appendProcessConfigDefinition(NodeBuilder $definition): void ->end() ->end(); - /** @var ArrayNodeDefinition $tasksArrayDefinition */ $tasksArrayDefinition = $definition ->arrayNode('tasks') ->useAttributeAsKey('code') - ->prototype('array'); + ->arrayPrototype(); // Process list $taskListDefinition = $tasksArrayDefinition @@ -190,7 +186,7 @@ protected function appendTaskConfigDefinition(NodeBuilder $definition): void $definition->scalarNode('help') ->defaultValue(''); $definition->arrayNode('options') - ->prototype('variable') + ->variablePrototype() ->end(); $definition->scalarNode('error_strategy') ->defaultNull(); @@ -203,7 +199,7 @@ protected function appendTaskConfigDefinition(NodeBuilder $definition): void ->beforeNormalization() ->ifString() ->then(static fn ($item): array => [$item])->end() - ->prototype('scalar'); + ->scalarPrototype(); } } } diff --git a/tests/DependencyInjection/CleverAgeProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeProcessExtensionTest.php index 8a941647..6002cf63 100644 --- a/tests/DependencyInjection/CleverAgeProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeProcessExtensionTest.php @@ -21,11 +21,42 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Yaml\Yaml; #[CoversClass(CleverAgeProcessExtension::class)] #[UsesClass(Configuration::class)] class CleverAgeProcessExtensionTest extends TestCase { + public function testEveryServiceDefinitionFileIsLoaded(): void + { + $container = new ContainerBuilder(); + (new CleverAgeProcessExtension())->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); + 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))); + } + } + } + public function testStopCheckersAreInjectedInTheProcessManager(): void { $container = new ContainerBuilder();