[Console] Fix ApplicationTest::testSetSignalsToDispatchEvent() when ran alone
Автор
Grégoire Pineau

Коммитер
Fabien Potencier
2 года назад 
Файлов изменено: 2
+42–9
c77433d
Tests/ApplicationTest.php
+34–9
@@ -64,6 +64,16 @@ | ||
putenv('SHELL_VERBOSITY'); | ||
unset($_ENV['SHELL_VERBOSITY']); | ||
unset($_SERVER['SHELL_VERBOSITY']); | ||
if (\function_exists('pcntl_signal')) { | ||
// We reset all signals to their default value to avoid side effects | ||
for ($i = 1; $i <= 15; ++$i) { | ||
if (9 === $i) { | ||
continue; | ||
} | ||
pcntl_signal($i, SIG_DFL); | ||
} | ||
} | ||
} | ||
public static function setUpBeforeClass(): void | ||
@@ -508,15 +518,7 @@ | ||
$application->setAutoExit(false); | ||
$tester = new ApplicationTester($application); | ||
$tester->run(['command' => 'foos:bar1'], ['decorated' => false]); | ||
$this->assertSame(' | ||
There are no commands defined in the "foos" namespace. | ||
Did you mean this? | ||
foo | ||
', $tester->getDisplay(true)); | ||
$this->assertStringEqualsFile(self::$fixturesPath.'/application.dont_run_alternative_namespace_name.txt', $tester->getDisplay(true)); | ||
} | ||
public function testCanRunAlternativeCommandName() | ||
@@ -1956,15 +1958,38 @@ | ||
$dispatcher = new EventDispatcher(); | ||
$dispatcher->addSubscriber($subscriber); | ||
// Since there is no signal handler, and by default PHP will stop even | ||
// on SIGUSR1, we need to register a blank handler to avoid the process | ||
// being stopped. | ||
$blankHandlerSignaled = false; | ||
pcntl_signal(\SIGUSR1, function () use (&$blankHandlerSignaled) { | ||
$blankHandlerSignaled = true; | ||
}); | ||
$application = $this->createSignalableApplication($command, $dispatcher); | ||
$application->setSignalsToDispatchEvent(\SIGUSR2); | ||
$this->assertSame(0, $application->run(new ArrayInput(['signal']))); | ||
$this->assertFalse($subscriber->signaled); | ||
$this->assertTrue($blankHandlerSignaled); | ||
// We reset the blank handler to false to make sure it is called again | ||
$blankHandlerSignaled = false; | ||
$application = $this->createSignalableApplication($command, $dispatcher); | ||
$application->setSignalsToDispatchEvent(\SIGUSR1); | ||
$this->assertSame(1, $application->run(new ArrayInput(['signal']))); | ||
$this->assertTrue($subscriber->signaled); | ||
$this->assertTrue($blankHandlerSignaled); | ||
// And now we test without the blank handler | ||
$blankHandlerSignaled = false; | ||
pcntl_signal(\SIGUSR1, SIG_DFL); | ||
$application = $this->createSignalableApplication($command, $dispatcher); | ||
$application->setSignalsToDispatchEvent(\SIGUSR1); | ||
$this->assertSame(1, $application->run(new ArrayInput(['signal']))); | ||
$this->assertTrue($subscriber->signaled); | ||
$this->assertFalse($blankHandlerSignaled); | ||
} | ||
public function testSignalableCommandInterfaceWithoutSignals() |
Tests/Fixtures/application.dont_run_alternative_namespace_name.txt
0 100644
+8–0
@@ -0,0 +1,8 @@ | ||
There are no commands defined in the "foos" namespace. | ||
Did you mean this? | ||
foo | ||
Cherry-pick
Команда cherry-pick позволяет выбрать отдельные коммиты из одной ветки и применить их к другой.