Skip to content

Commit 691bfda

Browse files
authored
IBX-10428: Fixed invokable commands failing to compile Container (#634)
1 parent d7bd603 commit 691bfda

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPass.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Ibexa\Bundle\Core\DependencyInjection\Compiler;
1010

11+
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputOption;
1213
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1314
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -19,6 +20,11 @@ public function process(ContainerBuilder $container): void
1920
foreach ($container->findTaggedServiceIds('console.command') as $id => $attributes) {
2021
$definition = $container->getDefinition($id);
2122

23+
$class = $definition->getClass();
24+
if ($class === null || !is_a($class, Command::class, true)) {
25+
continue;
26+
}
27+
2228
$definition->addMethodCall('addOption', [
2329
'siteaccess',
2430
null,

tests/bundle/Core/DependencyInjection/Compiler/ConsoleCommandPassTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Ibexa\Bundle\Core\DependencyInjection\Compiler\ConsoleCommandPass;
1212
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
13+
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputOption;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Definition;
@@ -23,7 +24,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void
2324

2425
public function testAddSiteaccessOption(): void
2526
{
26-
$commandDefinition = new Definition();
27+
$commandDefinition = new Definition(Command::class);
2728
$serviceId = 'some_service_id';
2829
$commandDefinition->addTag('console.command');
2930

@@ -41,4 +42,16 @@ public function testAddSiteaccessOption(): void
4142
]
4243
);
4344
}
45+
46+
public function testSkipsSiteaccessOptionOnInvokables(): void
47+
{
48+
$commandDefinition = new Definition();
49+
$serviceId = 'some_service_id';
50+
$commandDefinition->addTag('console.command');
51+
52+
$this->setDefinition($serviceId, $commandDefinition);
53+
$this->compile();
54+
55+
$this->assertContainerBuilderHasService($serviceId);
56+
}
4457
}

0 commit comments

Comments
 (0)