Skip to content

Commit

Permalink
[Console] Run commands when implements SignalableCommandInterface wit…
Browse files Browse the repository at this point in the history
…hout pcntl and they have'nt signals
  • Loading branch information
PaolaRuby authored and nicolas-grekas committed Jul 19, 2021
1 parent 1f6a5a7 commit ad63d0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -940,7 +940,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
}
}

if ($command instanceof SignalableCommandInterface) {
if ($command instanceof SignalableCommandInterface && ($this->signalsToDispatchEvent || $command->getSubscribedSignals())) {
if (!$this->signalRegistry) {
throw new RuntimeException('Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
}
Expand Down
15 changes: 14 additions & 1 deletion src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -36,6 +36,7 @@
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand Down Expand Up @@ -1861,6 +1862,18 @@ public function testSignal()
$this->assertTrue($command->signaled);
$this->assertTrue($dispatcherCalled);
}

public function testSignalableCommandInterfaceWithoutSignals()
{
$command = new SignableCommand();

$dispatcher = new EventDispatcher();
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher($dispatcher);
$application->add($command);
$this->assertSame(0, $application->run(new ArrayInput(['signal'])));
}
}

class CustomApplication extends Application
Expand Down Expand Up @@ -1928,7 +1941,7 @@ class SignableCommand extends Command implements SignalableCommandInterface

public function getSubscribedSignals(): array
{
return [\SIGALRM];
return SignalRegistry::isSupported() ? [\SIGALRM] : [];
}

public function handleSignal(int $signal): void
Expand Down

0 comments on commit ad63d0b

Please sign in to comment.