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
* [#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.

Expand Down
10 changes: 2 additions & 8 deletions src/DependencyInjection/CleverAgeProcessExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}
}
22 changes: 9 additions & 13 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

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;

/**
* 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
{
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -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
Expand Down Expand Up @@ -147,7 +144,7 @@ protected function appendProcessConfigDefinition(NodeBuilder $definition): void
->defaultTrue()
->end()
->arrayNode('options')
->prototype('variable')
->variablePrototype()
->end()
->end()
->arrayNode('logs')
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -203,7 +199,7 @@ protected function appendTaskConfigDefinition(NodeBuilder $definition): void
->beforeNormalization()
->ifString()
->then(static fn ($item): array => [$item])->end()
->prototype('scalar');
->scalarPrototype();
}
}
}
31 changes: 31 additions & 0 deletions tests/DependencyInjection/CleverAgeProcessExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading