@@ -774,6 +774,31 @@ public function testRunReturnsIntegerExitCode()
774774 $ this ->assertSame (4 , $ exitCode , '->run() returns integer exit code extracted from raised exception ' );
775775 }
776776
777+ public function testRunDispatchesIntegerExitCode ()
778+ {
779+ $ passedRightValue = false ;
780+
781+ // We can assume here that some other test asserts that the event is dispatched at all
782+ $ dispatcher = new EventDispatcher ();
783+ $ self = $ this ;
784+ $ dispatcher ->addListener ('console.terminate ' , function (ConsoleTerminateEvent $ event ) use ($ self , &$ passedRightValue ) {
785+ $ passedRightValue = (4 === $ event ->getExitCode ());
786+ });
787+
788+ $ application = new Application ();
789+ $ application ->setDispatcher ($ dispatcher );
790+ $ application ->setAutoExit (false );
791+
792+ $ application ->register ('test ' )->setCode (function (InputInterface $ input , OutputInterface $ output ) {
793+ throw new \Exception ('' , 4 );
794+ });
795+
796+ $ tester = new ApplicationTester ($ application );
797+ $ tester ->run (array ('command ' => 'test ' ));
798+
799+ $ this ->assertTrue ($ passedRightValue , '-> exit code 4 was passed in the console.terminate event ' );
800+ }
801+
777802 public function testRunReturnsExitCodeOneForExceptionCodeZero ()
778803 {
779804 $ exception = new \Exception ('' , 0 );
@@ -789,6 +814,31 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
789814 $ this ->assertSame (1 , $ exitCode , '->run() returns exit code 1 when exception code is 0 ' );
790815 }
791816
817+ public function testRunDispatchesExitCodeOneForExceptionCodeZero ()
818+ {
819+ $ passedRightValue = false ;
820+
821+ // We can assume here that some other test asserts that the event is dispatched at all
822+ $ dispatcher = new EventDispatcher ();
823+ $ self = $ this ;
824+ $ dispatcher ->addListener ('console.terminate ' , function (ConsoleTerminateEvent $ event ) use ($ self , &$ passedRightValue ) {
825+ $ passedRightValue = (1 === $ event ->getExitCode ());
826+ });
827+
828+ $ application = new Application ();
829+ $ application ->setDispatcher ($ dispatcher );
830+ $ application ->setAutoExit (false );
831+
832+ $ application ->register ('test ' )->setCode (function (InputInterface $ input , OutputInterface $ output ) {
833+ throw new \Exception ();
834+ });
835+
836+ $ tester = new ApplicationTester ($ application );
837+ $ tester ->run (array ('command ' => 'test ' ));
838+
839+ $ this ->assertTrue ($ passedRightValue , '-> exit code 1 was passed in the console.terminate event ' );
840+ }
841+
792842 /**
793843 * @expectedException \LogicException
794844 * @expectedExceptionMessage An option with shortcut "e" already exists.
0 commit comments