@@ -210,6 +210,76 @@ public function testAskAndValidate()
210
210
}
211
211
}
212
212
213
+ /**
214
+ * @dataProvider simpleAnswerProvider
215
+ */
216
+ public function testSelectChoiceFromSimpleChoices ($ providedAnswer , $ expectedValue )
217
+ {
218
+ $ possibleChoices = array (
219
+ 'My environment 1 ' ,
220
+ 'My environment 2 ' ,
221
+ 'My environment 3 ' ,
222
+ );
223
+
224
+ $ dialog = new QuestionHelper ();
225
+ $ dialog ->setInputStream ($ this ->getInputStream ($ providedAnswer ."\n" ));
226
+ $ helperSet = new HelperSet (array (new FormatterHelper ()));
227
+ $ dialog ->setHelperSet ($ helperSet );
228
+
229
+ $ question = new ChoiceQuestion ('Please select the environment to load ' , $ possibleChoices );
230
+ $ answer = $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question );
231
+
232
+ $ this ->assertSame ($ expectedValue , $ answer );
233
+ }
234
+
235
+ public function simpleAnswerProvider ()
236
+ {
237
+ return array (
238
+ array (0 , 'My environment 1 ' ),
239
+ array (1 , 'My environment 2 ' ),
240
+ array (2 , 'My environment 3 ' ),
241
+ array ('My environment 1 ' , 'My environment 1 ' ),
242
+ array ('My environment 2 ' , 'My environment 2 ' ),
243
+ array ('My environment 3 ' , 'My environment 3 ' ),
244
+ );
245
+ }
246
+
247
+ /**
248
+ * @dataProvider mixedKeysChoiceListAnswerProvider
249
+ */
250
+ public function testChoiceFromChoicelistWithMixedKeys ($ providedAnswer , $ expectedValue )
251
+ {
252
+ $ possibleChoices = array (
253
+ '0 ' => 'No environment ' ,
254
+ '1 ' => 'My environment 1 ' ,
255
+ 'env_2 ' => 'My environment 2 ' ,
256
+ 3 => 'My environment 3 ' ,
257
+ );
258
+
259
+ $ dialog = new QuestionHelper ();
260
+ $ dialog ->setInputStream ($ this ->getInputStream ($ providedAnswer ."\n" ));
261
+ $ helperSet = new HelperSet (array (new FormatterHelper ()));
262
+ $ dialog ->setHelperSet ($ helperSet );
263
+
264
+ $ question = new ChoiceQuestion ('Please select the environment to load ' , $ possibleChoices );
265
+ $ question ->setMaxAttempts (1 );
266
+ $ answer = $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question );
267
+
268
+ $ this ->assertSame ($ expectedValue , $ answer );
269
+ }
270
+
271
+ public function mixedKeysChoiceListAnswerProvider ()
272
+ {
273
+ return array (
274
+ array ('0 ' , '0 ' ),
275
+ array ('No environment ' , '0 ' ),
276
+ array ('1 ' , '1 ' ),
277
+ array ('env_2 ' , 'env_2 ' ),
278
+ array (3 , '3 ' ),
279
+ array ('My environment 1 ' , '1 ' ),
280
+ );
281
+ }
282
+
213
283
/**
214
284
* @dataProvider answerProvider
215
285
*/
@@ -227,6 +297,7 @@ public function testSelectChoiceFromChoiceList($providedAnswer, $expectedValue)
227
297
$ dialog ->setHelperSet ($ helperSet );
228
298
229
299
$ question = new ChoiceQuestion ('Please select the environment to load ' , $ possibleChoices );
300
+ $ question ->setMaxAttempts (1 );
230
301
$ answer = $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question );
231
302
232
303
$ this ->assertSame ($ expectedValue , $ answer );
0 commit comments