@@ -76,9 +76,9 @@ public function testWaitZero(): void
7676 $ time = time ();
7777 CLI ::wait (0 );
7878
79- $ this ->assertCloseEnough (0 , time () - $ time );
80-
8179 PhpStreamWrapper::restore ();
80+
81+ $ this ->assertCloseEnough (0 , time () - $ time );
8282 }
8383
8484 public function testPrompt (): void
@@ -90,9 +90,83 @@ public function testPrompt(): void
9090
9191 $ output = CLI ::prompt ('What is your favorite color? ' );
9292
93+ PhpStreamWrapper::restore ();
94+
9395 $ this ->assertSame ($ expected , $ output );
96+ }
97+
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 ' );
94106
95107 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 );
96170 }
97171
98172 public function testPromptByMultipleKeys (): void
@@ -105,14 +179,49 @@ public function testPromptByMultipleKeys(): void
105179 $ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
106180 $ output = CLI ::promptByMultipleKeys ('Select your hobbies: ' , $ options );
107181
182+ PhpStreamWrapper::restore ();
183+
108184 $ expected = [
109185 0 => 'Playing game ' ,
110186 1 => 'Sleep ' ,
111187 ];
188+ $ this ->assertSame ($ expected , $ output );
189+ }
190+
191+ public function testPromptByMultipleKeysInputNothing (): void
192+ {
193+ PhpStreamWrapper::register ();
194+
195+ $ input = '' ; // This is when you press the Enter key.
196+ PhpStreamWrapper::setContent ($ input );
112197
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+ ];
113206 $ 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 );
114218
115219 PhpStreamWrapper::restore ();
220+
221+ $ expected = [
222+ 0 => 'Playing game ' ,
223+ ];
224+ $ this ->assertSame ($ expected , $ output );
116225 }
117226
118227 public function testNewLine (): void
0 commit comments