8000 [Console] Run commands when implements SignalableCommandInterface wit… · symfony/symfony@ad63d0b · GitHub
[go: up one dir, main page]

Skip to content

Commit ad63d0b

Browse files
PaolaRubynicolas-grekas
authored andcommitted
[Console] Run commands when implements SignalableCommandInterface without pcntl and they have'nt signals
1 parent 1f6a5a7 commit ad63d0b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
940940
}
941941
}
942942

943-
if ($command instanceof SignalableCommandInterface) {
943+
if ($command instanceof SignalableCommandInterface && ($this->signalsToDispatchEvent || $command->getSubscribedSignals())) {
944944
if (!$this->signalRegistry) {
945945
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.');
946946
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Component\Console\Output\Output;
3737
use Symfony\Component\Console\Output\OutputInterface;
3838
use Symfony\Component\Console\Output\StreamOutput;
39+
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
3940
use Symfony\Component\Console\Tester\ApplicationTester;
4041
use Symfony\Component\DependencyInjection\ContainerBuilder;
4142
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -1861,6 +1862,18 @@ public function testSignal()
18611862
$this->assertTrue($command->signaled);
18621863
$this->assertTrue($dispatcherCalled);
18631864
}
1865+
1866+
public function testSignalableCommandInterfaceWithoutSignals()
1867+
{
1868+
$command = new SignableCommand();
1869+
1870+
$dispatcher = new EventDispatcher();
1871+
$application = new Application();
1872+
$application->setAutoExit(false);
1873+
$application->setDispatcher($dispatcher);
1874+
$application->add($command);
1875+
$this->assertSame(0, $application->run(new ArrayInput(['signal'])));
1876+
}
18641877
}
18651878

18661879
class CustomApplication extends Application
@@ -1928,7 +1941,7 @@ class SignableCommand extends Command implements SignalableCommandInterface
19281941

19291942
public function getSubscribedSignals(): array
19301943
{
1931-
return [\SIGALRM];
1944+
return SignalRegistry::isSupported() ? [\SIGALRM] : [];
19321945
}
19331946

19341947
public function handleSignal(int $signal): void

0 commit comments

Comments
 (0)
0