@@ -90,6 +90,63 @@ public function testAskChoice()
90
90
$ this ->assertEquals ('Superman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock (true ), $ this ->createOutputInterface (), $ question ));
91
91
}
92
92
93
+ public function testAskChoiceNonInteractive ()
94
+ {
95
+ $ questionHelper = new QuestionHelper ();
96
+
97
+ $ helperSet = new HelperSet (array (new FormatterHelper ()));
98
+ $ questionHelper ->setHelperSet ($ helperSet );
99
+ $ questionHelper ->setInputStream ($ this ->getInputStream ("\n1 \n 1 \nFabien \n1 \nFabien \n1 \n0,2 \n 0 , 2 \n\n\n" ));
100
+
101
+ $ heroes = array ('Superman ' , 'Batman ' , 'Spiderman ' );
102
+
103
+ $ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , '0 ' );
104
+
105
+ $ this ->assertSame ('Superman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
106
+
107
+ $ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , 'Batman ' );
108
+ $ this ->assertSame ('Batman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
109
+
110
+ $ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , null );
111
+ $ this ->assertNull ($ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
112
+
113
+ $ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , '0 ' );
114
+ $ question ->setValidator (null );
115
+ $ this ->assertSame ('Superman ' , $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
116
+
117
+ try {
118
+ $ question = new ChoiceQuestion ('What is your favorite superhero? ' , $ heroes , null );
119
+ $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question );
120
+ } catch (\InvalidArgumentException $ e ) {
121
+ $ this ->assertSame ('Value "" is invalid ' , $ e ->getMessage ());
122
+ }
123
+
124
+ $ question = new ChoiceQuestion ('Who are your favorite superheros? ' , $ heroes , '0, 1 ' );
125
+ $ question ->setMultiselect (true );
126
+ $ this ->assertSame (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
127
+
128
+ $ question = new ChoiceQuestion ('Who are your favorite superheros? ' , $ heroes , '0, 1 ' );
129
+ $ question ->setMultiselect (true );
130
+ $ question ->setValidator (null );
131
+ $ this ->assertSame (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
132
+
133
+ $ question = new ChoiceQuestion ('Who are your favorite superheros? ' , $ heroes , '0, Batman ' );
134
+ $ question ->setMultiselect (true );
135
+ $ this ->assertSame (array ('Superman ' , 'Batman ' ), $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
136
+
137
+ $ question = new ChoiceQuestion ('Who are your favorite superheros? ' , $ heroes , null );
138
+ $ question ->setMultiselect (true );
139
+ $ this ->assertNull ($ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question ));
140
+
141
+ try {
142
+ $ question = new ChoiceQuestion ('Who are your favorite superheros? ' , $ heroes , '' );
143
+ $ question ->setMultiselect (true );
144
+ $ questionHelper ->ask ($ this ->createInputInterfaceMock (false ), $ this ->createOutputInterface (), $ question );
145
+ } catch (\InvalidArgumentException $ e ) {
146
+ $ this ->assertSame ('Value "" is invalid ' , $ e ->getMessage ());
147
+ }
148
+ }
149
+
93
150
public function testAsk ()
94
151
{
95
152
$ dialog = new QuestionHelper ();
0 commit comments