diff --git a/DependencyInjection/Compiler/GroupRunnersCompilerPass.php b/DependencyInjection/Compiler/GroupRunnersCompilerPass.php index 4b5e4ee4..672a2bb2 100644 --- a/DependencyInjection/Compiler/GroupRunnersCompilerPass.php +++ b/DependencyInjection/Compiler/GroupRunnersCompilerPass.php @@ -2,6 +2,7 @@ namespace Liip\MonitorBundle\DependencyInjection\Compiler; +use Liip\MonitorBundle\Runner; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -35,10 +36,12 @@ public function process(ContainerBuilder $container): void $runners = []; foreach ($groups as $group) { $container->setDefinition('liip_monitor.runner_'.$group, clone $definition); + $container->registerAliasForArgument('liip_monitor.runner_'.$group, Runner::class, $group.'Runner'); $runners[] = 'liip_monitor.runner_'.$group; } $container->setAlias('liip_monitor.runner', 'liip_monitor.runner_'.$defaultGroup); + $container->setAlias(Runner::class, 'liip_monitor.runner'); $runner = $container->getAlias('liip_monitor.runner'); $runner->setPublic(true); @@ -48,7 +51,7 @@ public function process(ContainerBuilder $container): void private function getGroups(array $services): array { $groups = []; - foreach ($services as $serviceId => $tags) { + foreach ($services as $tags) { foreach ($tags as $attributes) { if (!empty($attributes['group'])) { $groups[$attributes['group']] = true; diff --git a/Tests/DependencyInjection/Compiler/GroupRunnersCompilerPassTest.php b/Tests/DependencyInjection/Compiler/GroupRunnersCompilerPassTest.php index 9524b00a..3c8da4f7 100644 --- a/Tests/DependencyInjection/Compiler/GroupRunnersCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/GroupRunnersCompilerPassTest.php @@ -3,6 +3,7 @@ namespace Liip\MonitorBundle\Tests\DependencyInjection\Compiler; use Liip\MonitorBundle\DependencyInjection\Compiler\GroupRunnersCompilerPass; +use Liip\MonitorBundle\Runner; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -35,6 +36,12 @@ public function testProcess(): void $this->assertContainerBuilderHasService('liip_monitor.runner_foobar'); $this->assertContainerBuilderHasService('liip_monitor.runner_bar'); $this->assertContainerBuilderHasService('liip_monitor.runner_baz'); + $this->assertContainerBuilderHasAlias(Runner::class.' $fooRunner', 'liip_monitor.runner_foo'); + $this->assertContainerBuilderHasAlias(Runner::class.' $foobarRunner', 'liip_monitor.runner_foobar'); + $this->assertContainerBuilderHasAlias(Runner::class.' $barRunner', 'liip_monitor.runner_bar'); + $this->assertContainerBuilderHasAlias(Runner::class.' $bazRunner', 'liip_monitor.runner_baz'); + $this->assertContainerBuilderHasAlias(Runner::class.' $groupeParDéfautRunner', 'liip_monitor.runner_'.$defaultGroup); + $this->assertContainerBuilderHasAlias(Runner::class, 'liip_monitor.runner'); } protected function registerCompilerPass(ContainerBuilder $container): void