Skip to content

Commit

Permalink
Merge branch '5.4' into 6.2
Browse files Browse the repository at this point in the history
* 5.4:
  [Console] Fix ApplicationTest::testSetSignalsToDispatchEvent() when ran alone
  • Loading branch information
fabpot committed Feb 25, 2023
2 parents 0a3c371 + c77433d commit cbad09e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
43 changes: 34 additions & 9 deletions Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ protected function tearDown(): void
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
Expand Down Expand Up @@ -509,15 +519,7 @@ public function testDontRunAlternativeNamespaceName()
$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()
Expand Down Expand Up @@ -1992,15 +1994,38 @@ public function testSetSignalsToDispatchEvent()
$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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


There are no commands defined in the "foos" namespace.

Did you mean this?
foo


0 comments on commit cbad09e

Please sign in to comment.