Skip to content

Commit cbad09e

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: [Console] Fix ApplicationTest::testSetSignalsToDispatchEvent() when ran alone
2 parents 0a3c371 + c77433d commit cbad09e

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

Tests/ApplicationTest.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ protected function tearDown(): void
6666
putenv('SHELL_VERBOSITY');
6767
unset($_ENV['SHELL_VERBOSITY']);
6868
unset($_SERVER['SHELL_VERBOSITY']);
69+
70+
if (\function_exists('pcntl_signal')) {
71+
// We reset all signals to their default value to avoid side effects
72+
for ($i = 1; $i <= 15; ++$i) {
73+
if (9 === $i) {
74+
continue;
75+
}
76+
pcntl_signal($i, SIG_DFL);
77+
}
78+
}
6979
}
7080

7181
public static function setUpBeforeClass(): void
@@ -509,15 +519,7 @@ public function testDontRunAlternativeNamespaceName()
509519
$application->setAutoExit(false);
510520
$tester = new ApplicationTester($application);
511521
$tester->run(['command' => 'foos:bar1'], ['decorated' => false]);
512-
$this->assertSame('
513-
514-
There are no commands defined in the "foos" namespace.
515-
516-
Did you mean this?
517-
foo
518-
519-
520-
', $tester->getDisplay(true));
522+
$this->assertStringEqualsFile(self::$fixturesPath.'/application.dont_run_alternative_namespace_name.txt', $tester->getDisplay(true));
521523
}
522524

523525
public function testCanRunAlternativeCommandName()
@@ -1992,15 +1994,38 @@ public function testSetSignalsToDispatchEvent()
19921994
$dispatcher = new EventDispatcher();
19931995
$dispatcher->addSubscriber($subscriber);
19941996

1997+
// Since there is no signal handler, and by default PHP will stop even
1998+
// on SIGUSR1, we need to register a blank handler to avoid the process
1999+
// being stopped.
2000+
$blankHandlerSignaled = false;
2001+
pcntl_signal(\SIGUSR1, function () use (&$blankHandlerSignaled) {
2002+
$blankHandlerSignaled = true;
2003+
});
2004+
19952005
$application = $this->createSignalableApplication($command, $dispatcher);
19962006
$application->setSignalsToDispatchEvent(\SIGUSR2);
19972007
$this->assertSame(0, $application->run(new ArrayInput(['signal'])));
19982008
$this->assertFalse($subscriber->signaled);
2009+
$this->assertTrue($blankHandlerSignaled);
2010+
2011+
// We reset the blank handler to false to make sure it is called again
2012+
$blankHandlerSignaled = false;
2013+
2014+
$application = $this->createSignalableApplication($command, $dispatcher);
2015+
$application->setSignalsToDispatchEvent(\SIGUSR1);
2016+
$this->assertSame(1, $application->run(new ArrayInput(['signal'])));
2017+
$this->assertTrue($subscriber->signaled);
2018+
$this->assertTrue($blankHandlerSignaled);
2019+
2020+
// And now we test without the blank handler
2021+
$blankHandlerSignaled = false;
2022+
pcntl_signal(\SIGUSR1, SIG_DFL);
19992023

20002024
$application = $this->createSignalableApplication($command, $dispatcher);
20012025
$application->setSignalsToDispatchEvent(\SIGUSR1);
20022026
$this->assertSame(1, $application->run(new ArrayInput(['signal'])));
20032027
$this->assertTrue($subscriber->signaled);
2028+
$this->assertFalse($blankHandlerSignaled);
20042029
}
20052030

20062031
public function testSignalableCommandInterfaceWithoutSignals()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
There are no commands defined in the "foos" namespace.
4+
5+
Did you mean this?
6+
foo
7+
8+

0 commit comments

Comments
 (0)