1717use Symfony \Component \Console \Helper \HelperSet ;
1818use Symfony \Component \Console \Helper \QuestionHelper ;
1919use Symfony \Component \Console \Output \Output ;
20+ use Symfony \Component \Console \Question \ChoiceQuestion ;
2021use Symfony \Component \Console \Question \Question ;
2122use Symfony \Component \Console \Style \SymfonyStyle ;
2223use Symfony \Component \Console \Tester \CommandTester ;
@@ -139,7 +140,7 @@ public function testCommandWithDefaultInputs()
139140
140141 /**
141142 * @expectedException \RuntimeException
142- * @expectedMessage Aborted
143+ * @expectedExceptionMessage Aborted.
143144 */
144145 public function testCommandWithWrongInputsNumber ()
145146 {
@@ -153,13 +154,40 @@ public function testCommandWithWrongInputsNumber()
153154 $ command ->setHelperSet (new HelperSet ([new QuestionHelper ()]));
154155 $ command ->setCode (function ($ input , $ output ) use ($ questions , $ command ) {
155156 $ helper = $ command ->getHelper ('question ' );
157+ $ helper ->ask ($ input , $ output , new ChoiceQuestion ('choice ' , ['a ' , 'b ' ]));
158+ $ helper ->ask ($ input , $ output , new Question ($ questions [0 ]));
159+ $ helper ->ask ($ input , $ output , new Question ($ questions [1 ]));
160+ $ helper ->ask ($ input , $ output , new Question ($ questions [2 ]));
161+ });
162+
163+ $ tester = new CommandTester ($ command );
164+ $ tester ->setInputs (['a ' , 'Bobby ' , 'Fine ' ]);
165+ $ tester ->execute ([]);
166+ }
167+
168+ /**
169+ * @expectedException \RuntimeException
170+ * @expectedExceptionMessage Aborted.
171+ */
172+ public function testCommandWithQuestionsButNoInputs ()
173+ {
174+ $ questions = [
175+ 'What \'s your name? ' ,
176+ 'How are you? ' ,
177+ 'Where do you come from? ' ,
178+ ];
179+
180+ $ command = new Command ('foo ' );
181+ $ command ->setHelperSet (new HelperSet ([new QuestionHelper ()]));
182+ $ command ->setCode (function ($ input , $ output ) use ($ questions , $ command ) {
183+ $ helper = $ command ->getHelper ('question ' );
184+ $ helper ->ask ($ input , $ output , new ChoiceQuestion ('choice ' , ['a ' , 'b ' ]));
156185 $ helper ->ask ($ input , $ output , new Question ($ questions [0 ]));
157186 $ helper ->ask ($ input , $ output , new Question ($ questions [1 ]));
158187 $ helper ->ask ($ input , $ output , new Question ($ questions [2 ]));
159188 });
160189
161190 $ tester = new CommandTester ($ command );
162- $ tester ->setInputs (['Bobby ' , 'Fine ' ]);
163191 $ tester ->execute ([]);
164192 }
165193
0 commit comments