@@ -943,6 +943,63 @@ public function testRunWithDispatcherSkippingCommand()
943
943
$ this ->assertEquals (ConsoleCommandEvent::RETURN_CODE_DISABLED , $ exitCode );
944
944
}
945
945
946
+ public function testRunWithDispatcherAccessingInputOptions ()
947
+ {
948
+ $ noInteractionValue = null ;
949
+ $ quietValue = null ;
950
+
951
+ $ dispatcher = $ this ->getDispatcher ();
952
+ $ dispatcher ->addListener ('console.command ' , function (ConsoleCommandEvent $ event ) use (&$ noInteractionValue , &$ quietValue ) {
953
+ $ input = $ event ->getInput ();
954
+
955
+ $ noInteractionValue = $ input ->getOption ('no-interaction ' );
956
+ $ quietValue = $ input ->getOption ('quiet ' );
957
+ });
958
+
959
+ $ application = new Application ();
960
+ $ application ->setDispatcher ($ dispatcher );
961
+ $ application ->setAutoExit (false );
962
+
963
+ $ application ->register ('foo ' )->setCode (function (InputInterface $ input , OutputInterface $ output ) {
964
+ $ output ->write ('foo. ' );
965
+ });
966
+
967
+ $ tester = new ApplicationTester ($ application );
968
+ $ tester ->run (array ('command ' => 'foo ' , '--no-interaction ' => true ));
969
+
970
+ $ this ->assertTrue ($ noInteractionValue );
971
+ $ this ->assertFalse ($ quietValue );
972
+ }
973
+
974
+ public function testRunWithDispatcherAddingInputOptions ()
975
+ {
976
+ $ extraValue = null ;
977
+
978
+ $ dispatcher = $ this ->getDispatcher ();
979
+ $ dispatcher ->addListener ('console.command ' , function (ConsoleCommandEvent $ event ) use (&$ extraValue ) {
980
+ $ definition = $ event ->getCommand ()->getDefinition ();
981
+ $ input = $ event ->getInput ();
982
+
983
+ $ definition ->addOption (new InputOption ('extra ' , null , InputOption::VALUE_REQUIRED ));
984
+ $ input ->bind ($ definition );
985
+
986
+ $ extraValue = $ input ->getOption ('extra ' );
987
+ });
988
+
989
+ $ application = new Application ();
990
+ $ application ->setDispatcher ($ dispatcher );
991
+ $ application ->setAutoExit (false );
992
+
993
+ $ application ->register ('foo ' )->setCode (function (InputInterface $ input , OutputInterface $ output ) {
994
+ $ output ->write ('foo. ' );
995
+ });
996
+
997
+ $ tester = new ApplicationTester ($ application );
998
+ $ tester ->run (array ('command ' => 'foo ' , '--extra ' => 'some test value ' ));
999
+
1000
+ $ this ->assertEquals ('some test value ' , $ extraValue );
1001
+ }
1002
+
946
1003
public function testTerminalDimensions ()
947
1004
{
948
1005
$ application = new Application ();
0 commit comments