Skip to content

Commit

Permalink
[Console] fix managing signals when commands are lazy loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 11, 2021
1 parent da9c0be commit ecc138b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1902,7 +1903,7 @@ public function __construct()
}
}

class LazyCommand extends Command
class LazyTestCommand extends Command
{
public function execute(InputInterface $input, OutputInterface $output): int
{
Expand Down

0 comments on commit ecc138b

Please sign in to comment.