@@ -76,9 +76,9 @@ public function testWaitZero(): void
76
76
$ time = time ();
77
77
CLI ::wait (0 );
78
78
79
- $ this ->assertCloseEnough (0 , time () - $ time );
80
-
81
79
PhpStreamWrapper::restore ();
80
+
81
+ $ this ->assertCloseEnough (0 , time () - $ time );
82
82
}
83
83
84
84
public function testPrompt (): void
@@ -90,9 +90,83 @@ public function testPrompt(): void
90
90
91
91
$ output = CLI ::prompt ('What is your favorite color? ' );
92
92
93
+ PhpStreamWrapper::restore ();
94
+
93
95
$ 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 ' );
94
106
95
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 );
96
170
}
97
171
98
172
public function testPromptByMultipleKeys (): void
@@ -105,14 +179,49 @@ public function testPromptByMultipleKeys(): void
105
179
$ options = ['Playing game ' , 'Sleep ' , 'Badminton ' ];
106
180
$ output = CLI ::promptByMultipleKeys ('Select your hobbies: ' , $ options );
107
181
182
+ PhpStreamWrapper::restore ();
183
+
108
184
$ expected = [
109
185
0 => 'Playing game ' ,
110
186
1 => 'Sleep ' ,
111
187
];
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 );
112
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
+ ];
113
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 );
114
218
115
219
PhpStreamWrapper::restore ();
220
+
221
+ $ expected = [
222
+ 0 => 'Playing game ' ,
223
+ ];
224
+ $ this ->assertSame ($ expected , $ output );
116
225
}
117
226
118
227
public function testNewLine (): void
0 commit comments