Skip to content

Commit ecc138b

Browse files
[Console] fix managing signals when commands are lazy loaded
1 parent da9c0be commit ecc138b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ public function doRun(InputInterface $input, OutputInterface $output)
287287
$command = $this->find($alternative);
288288
}
289289

290+
if ($command instanceof LazyCommand) {
291+
$command = $command->getCommand();
292+
}
293+
290294
$this->runningCommand = $command;
291295
$exitCode = $this->doRunCommand($command, $input, $output);
292296
$this->runningCommand = null;

Tests/ApplicationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Command\HelpCommand;
18+
use Symfony\Component\Console\Command\LazyCommand;
1819
use Symfony\Component\Console\Command\SignalableCommandInterface;
1920
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
2021
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
@@ -1672,7 +1673,7 @@ public function testRunLazyCommandService()
16721673
$container = new ContainerBuilder();
16731674
$container->addCompilerPass(new AddConsoleCommandPass());
16741675
$container
1675-
->register('lazy-command', LazyCommand::class)
1676+
->register('lazy-command', LazyTestCommand::class)
16761677
->addTag('console.command', ['command' => 'lazy:command'])
16771678
->addTag('console.command', ['command' => 'lazy:alias'])
16781679
->addTag('console.command', ['command' => 'lazy:alias2']);
@@ -1847,7 +1848,7 @@ public function testSignal()
18471848
$application->setAutoExit(false);
18481849
$application->setDispatcher($dispatcher);
18491850
$application->setSignalsToDispatchEvent(\SIGALRM);
1850-
$application->add($command);
1851+
$application->add(new LazyCommand('signal', [], '', false, function () use ($command) { return $command; }, true));
18511852

18521853
$this->assertFalse($command->signaled);
18531854
$this->assertFalse($dispatcherCalled);
@@ -1902,7 +1903,7 @@ public function __construct()
19021903
}
19031904
}
19041905

1905-
class LazyCommand extends Command
1906+
class LazyTestCommand extends Command
19061907
{
19071908
public function execute(InputInterface $input, OutputInterface $output): int
19081909
{

0 commit comments

Comments
 (0)