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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Ibexa\Bundle\Core\DependencyInjection\Compiler;

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

$class = $definition->getClass();
if ($class === null || !is_a($class, Command::class, true)) {
Comment thread
Steveb-p marked this conversation as resolved.
continue;
}

$definition->addMethodCall('addOption', [
'siteaccess',
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

public function testAddSiteaccessOption(): void
{
$commandDefinition = new Definition();
$commandDefinition = new Definition(Command::class);
$serviceId = 'some_service_id';
$commandDefinition->addTag('console.command');

Expand All @@ -41,4 +42,16 @@ public function testAddSiteaccessOption(): void
]
);
}

public function testSkipsSiteaccessOptionOnInvokables(): void
{
$commandDefinition = new Definition();
$serviceId = 'some_service_id';
$commandDefinition->addTag('console.command');

$this->setDefinition($serviceId, $commandDefinition);
$this->compile();

$this->assertContainerBuilderHasService($serviceId);
}
}
Loading