@@ -143,27 +143,39 @@ public function testAskHiddenResponse()
143143 $ this ->assertEquals ('8AM ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
144144 }
145145
146- public function testAskConfirmation ()
146+ /**
147+ * @dataProvider getAskConfirmationData
148+ */
149+ public function testAskConfirmation ($ question , $ expected , $ default = true )
147150 {
148151 $ dialog = new QuestionHelper ();
149152
150- $ dialog ->setInputStream ($ this ->getInputStream ("\n\n" ));
151- $ question = new ConfirmationQuestion ('Do you like French fries? ' );
152- $ this ->assertTrue ($ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
153- $ question = new ConfirmationQuestion ('Do you like French fries? ' , false );
154- $ this ->assertFalse ($ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
153+ $ dialog ->setInputStream ($ this ->getInputStream ($ question ."\n" ));
154+ $ question = new ConfirmationQuestion ('Do you like French fries? ' , $ default );
155+ $ this ->assertEquals ($ expected , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ), 'confirmation question should ' .($ expected ? 'pass ' : 'cancel ' ));
156+ }
155157
156- $ dialog ->setInputStream ($ this ->getInputStream ("y \nyes \n" ));
157- $ question = new ConfirmationQuestion ('Do you like French fries? ' , false );
158+ public function getAskConfirmationData ()
159+ {
160+ return array (
161+ array ('' , true ),
162+ array ('' , false , false ),
163+ array ('y ' , true ),
164+ array ('yes ' , true ),
165+ array ('n ' , false ),
166+ array ('no ' , false ),
167+ );
168+ }
169+
170+ public function testAskConfirmationWithCustomTrueAnswer ()
171+ {
172+ $ dialog = new QuestionHelper ();
173+
174+ $ dialog ->setInputStream ($ this ->getInputStream ("j \ny \n" ));
175+ $ question = new ConfirmationQuestion ('Do you like French fries? ' , false , '/^(j|y)/i ' );
158176 $ this ->assertTrue ($ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
159- $ question = new ConfirmationQuestion ('Do you like French fries? ' , false );
177+ $ question = new ConfirmationQuestion ('Do you like French fries? ' , false , ' /^(j|y)/i ' );
160178 $ this ->assertTrue ($ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
161-
162- $ dialog ->setInputStream ($ this ->getInputStream ("n \nno \n" ));
163- $ question = new ConfirmationQuestion ('Do you like French fries? ' , true );
164- $ this ->assertFalse ($ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
165- $ question = new ConfirmationQuestion ('Do you like French fries? ' , true );
166- $ this ->assertFalse ($ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
167179 }
168180
169181 public function testAskAndValidate ()
0 commit comments