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