@@ -95,6 +95,80 @@ public function testPrompt(): void
9595 $ this ->assertSame ($ expected , $ output );
9696 }
9797
98+ public function testPromptInputNothing (): void
99+ {
100+ PhpStreamWrapper::register ();
101+
102+ $ input = '' ;
103+ PhpStreamWrapper::setContent ($ input );
104+
105+ $ output = CLI ::prompt ('What is your favorite color? ' , 'red ' );
106+
107+ PhpStreamWrapper::restore ();
108+
109+ $ this ->assertSame ('red ' , $ output );
110+ }
111+
112+ public function testPromptInputZero (): void
113+ {
114+ PhpStreamWrapper::register ();
115+
116+ $ input = '0 ' ;
117+ PhpStreamWrapper::setContent ($ input );
118+
119+ $ output = CLI ::prompt ('What is your favorite number? ' , '7 ' );
120+
121+ PhpStreamWrapper::restore ();
122+
123+ $ this ->assertSame ('0 ' , $ output );
124+ }
125+
126+ public function testPromptByKey (): void
127+ {
128+ PhpStreamWrapper::register ();
129+
130+ $ input = '1 ' ;
131+ PhpStreamWrapper::setContent ($ input );
132+
133+ $ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
134+ $ output = CLI ::promptByKey ('Select your hobbies: ' , $ options );
135+
136+ PhpStreamWrapper::restore ();
137+
138+ $ this ->assertSame ($ input , $ output );
139+ }
140+
141+ public function testPromptByKeyInputNothing (): void
142+ {
143+ PhpStreamWrapper::register ();
144+
145+ $ input = '' ; // This is when you press the Enter key.
146+ PhpStreamWrapper::setContent ($ input );
147+
148+ $ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
149+ $ output = CLI ::promptByKey ('Select your hobbies: ' , $ options );
150+
151+ PhpStreamWrapper::restore ();
152+
153+ $ expected = '0 ' ;
154+ $ this ->assertSame ($ expected , $ output );
155+ }
156+
157+ public function testPromptByKeyInputZero (): void
158+ {
159+ PhpStreamWrapper::register ();
160+
161+ $ input = '0 ' ;
162+ PhpStreamWrapper::setContent ($ input );
163+
164+ $ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
165+ $ output = CLI ::promptByKey ('Select your hobbies: ' , $ options );
166+
167+ PhpStreamWrapper::restore ();
168+
169+ $ this ->assertSame ($ input , $ output );
170+ }
171+
98172 public function testPromptByMultipleKeys (): void
99173 {
100174 PhpStreamWrapper::register ();
@@ -114,6 +188,42 @@ public function testPromptByMultipleKeys(): void
114188 $ this ->assertSame ($ expected , $ output );
115189 }
116190
191+ public function testPromptByMultipleKeysInputNothing (): void
192+ {
193+ PhpStreamWrapper::register ();
194+
195+ $ input = '' ; // This is when you press the Enter key.
196+ PhpStreamWrapper::setContent ($ input );
197+
198+ $ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
199+ $ output = CLI ::promptByMultipleKeys ('Select your hobbies: ' , $ options );
200+
201+ PhpStreamWrapper::restore ();
202+
203+ $ expected = [
204+ 0 => 'Playing game ' ,
205+ ];
206+ $ this ->assertSame ($ expected , $ output );
207+ }
208+
209+ public function testPromptByMultipleKeysInputZero (): void
210+ {
211+ PhpStreamWrapper::register ();
212+
213+ $ input = '0 ' ;
214+ PhpStreamWrapper::setContent ($ input );
215+
216+ $ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
217+ $ output = CLI ::promptByMultipleKeys ('Select your hobbies: ' , $ options );
218+
219+ PhpStreamWrapper::restore ();
220+
221+ $ expected = [
222+ 0 => 'Playing game ' ,
223+ ];
224+ $ this ->assertSame ($ expected , $ output );
225+ }
226+
117227 public function testNewLine (): void
118228 {
119229 $ this ->expectOutputString ('' );
0 commit comments