@@ -143,27 +143,39 @@ public function testAskHiddenResponse()
143
143
$ this ->assertEquals ('8AM ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
144
144
}
145
145
146
- public function testAskConfirmation ()
146
+ /**
147
+ * @dataProvider getAskConfirmationData
148
+ */
149
+ public function testAskConfirmation ($ question , $ expected , $ default = true )
147
150
{
148
151
$ dialog = new QuestionHelper ();
149
152
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
+ }
155
157
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 ' );
158
176
$ 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 ' );
160
178
$ 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 ));
167
179
}
168
180
169
181
public function testAskAndValidate ()
0 commit comments