From ecc138be35272271a77bc8f384fb0c57be671bde Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 11 Jun 2021 15:29:40 +0200 Subject: [PATCH] [Console] fix managing signals when commands are lazy loaded --- Application.php | 4 ++++ Tests/ApplicationTest.php | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Application.php b/Application.php index 426b3c4d6..9cdcef88c 100644 --- a/Application.php +++ b/Application.php @@ -287,6 +287,10 @@ public function doRun(InputInterface $input, OutputInterface $output) $command = $this->find($alternative); } + if ($command instanceof LazyCommand) { + $command = $command->getCommand(); + } + $this->runningCommand = $command; $exitCode = $this->doRunCommand($command, $input, $output); $this->runningCommand = null; diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index b3958226b..361e174cd 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\HelpCommand; +use Symfony\Component\Console\Command\LazyCommand; use Symfony\Component\Console\Command\SignalableCommandInterface; use Symfony\Component\Console\CommandLoader\FactoryCommandLoader; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; @@ -1672,7 +1673,7 @@ public function testRunLazyCommandService() $container = new ContainerBuilder(); $container->addCompilerPass(new AddConsoleCommandPass()); $container - ->register('lazy-command', LazyCommand::class) + ->register('lazy-command', LazyTestCommand::class) ->addTag('console.command', ['command' => 'lazy:command']) ->addTag('console.command', ['command' => 'lazy:alias']) ->addTag('console.command', ['command' => 'lazy:alias2']); @@ -1847,7 +1848,7 @@ public function testSignal() $application->setAutoExit(false); $application->setDispatcher($dispatcher); $application->setSignalsToDispatchEvent(\SIGALRM); - $application->add($command); + $application->add(new LazyCommand('signal', [], '', false, function () use ($command) { return $command; }, true)); $this->assertFalse($command->signaled); $this->assertFalse($dispatcherCalled); @@ -1902,7 +1903,7 @@ public function __construct() } } -class LazyCommand extends Command +class LazyTestCommand extends Command { public function execute(InputInterface $input, OutputInterface $output): int {