@@ -509,12 +509,12 @@ public function testDontRunAlternativeNamespaceName()
509
509
$ tester = new ApplicationTester ($ application );
510
510
$ tester ->run (['command ' => 'foos:bar1 ' ], ['decorated ' => false ]);
511
511
$ this ->assertSame ('
512
-
513
- There are no commands defined in the "foos" namespace.
514
-
515
- Did you mean this?
516
- foo
517
-
512
+
513
+ There are no commands defined in the "foos" namespace.
514
+
515
+ Did you mean this?
516
+ foo
517
+
518
518
519
519
' , $ tester ->getDisplay (true ));
520
520
}
@@ -1990,6 +1990,19 @@ public function testSignalableCommandHandlerCalledAfterEventListener()
1990
1990
$ this ->assertSame ([SignalEventSubscriber::class, SignableCommand::class], $ command ->signalHandlers );
1991
1991
}
1992
1992
1993
+ public function testSignalableCommandDoesNotInterruptedOnTermSignals ()
1994
+ {
1995
+ $ command = new TerminatableCommand (true , \SIGINT );
1996
+ $ command ->exitCode = 129 ;
1997
+
1998
+ $ dispatcher = new EventDispatcher ();
1999
+ $ application = new Application ();
2000
+ $ application ->setAutoExit (false );
2001
+ $ application ->setDispatcher ($ dispatcher );
2002
+ $ application ->add ($ command );
2003
+ $ this ->assertSame (129 , $ application ->run (new ArrayInput (['signal ' ])));
2004
+ }
2005
+
1993
2006
/**
1994
2007
* @group tty
1995
2008
*/
@@ -2091,28 +2104,30 @@ public function isEnabled(): bool
2091
2104
class BaseSignableCommand extends Command
2092
2105
{
2093
2106
public $ signaled = false ;
2107
+ public $ exitCode = 1 ;
2094
2108
public $ signalHandlers = [];
2095
2109
public $ loop = 1000 ;
2096
2110
private $ emitsSignal ;
2111
+ private $ signal ;
2097
2112
2098
2113
protected static $ defaultName = 'signal ' ;
2099
2114
2100
- public function __construct (bool $ emitsSignal = true )
2101
- {
2115
+ public function __construct (bool $ emitsSignal = true , int $ signal = \SIGUSR1 ) {
2102
2116
parent ::__construct ();
2103
2117
$ this ->emitsSignal = $ emitsSignal ;
2118
+ $ this ->signal = $ signal ;
2104
2119
}
2105
2120
2106
2121
protected function execute (InputInterface $ input , OutputInterface $ output ): int
2107
2122
{
2108
2123
if ($ this ->emitsSignal ) {
2109
- posix_kill (posix_getpid (), SIGUSR1 );
2124
+ posix_kill (posix_getpid (), $ this -> signal );
2110
2125
}
2111
2126
2112
2127
for ($ i = 0 ; $ i < $ this ->loop ; ++$ i ) {
2113
2128
usleep (100 );
2114
2129
if ($ this ->signaled ) {
2115
- return 1 ;
2130
+ return $ this -> exitCode ;
2116
2131
}
2117
2132
}
2118
2133
@@ -2136,6 +2151,22 @@ public function handleSignal(int $signal): void
2136
2151
}
2137
2152
}
2138
2153
2154
+ class TerminatableCommand extends BaseSignableCommand implements SignalableCommandInterface
2155
+ {
2156
+ protected static $ defaultName = 'signal ' ;
2157
+
2158
+ public function getSubscribedSignals (): array
2159
+ {
2160
+ return SignalRegistry::isSupported () ? [\SIGINT ] : [];
2161
+ }
2162
+
2163
+ public function handleSignal (int $ signal ): void
2164
+ {
2165
+ $ this ->signaled = true ;
2166
+ $ this ->signalHandlers [] = __CLASS__ ;
2167
+ }
2168
+ }
2169
+
2139
2170
class SignalEventSubscriber implements EventSubscriberInterface
2140
2171
{
2141
2172
public $ signaled = false ;
0 commit comments