|
10 | 10 | use function Laravel\Prompts\multisearch; |
11 | 11 | use function Laravel\Prompts\multiselect; |
12 | 12 | use function Laravel\Prompts\password; |
| 13 | +use function Laravel\Prompts\search; |
13 | 14 | use function Laravel\Prompts\select; |
14 | 15 | use function Laravel\Prompts\text; |
15 | 16 | use function Laravel\Prompts\textarea; |
@@ -168,7 +169,8 @@ public function handle() |
168 | 169 | $this |
169 | 170 | ->artisan('test:select') |
170 | 171 | ->expectsChoice('What is your name?', 'Jane', ['John', 'Jane']) |
171 | | - ->expectsChoice('What is your title?', 'Dr', ['Dr']) |
| 172 | + ->expectsQuestion('What is your title?', 'D') |
| 173 | + ->expectsChoice('What is your title?', ['Dr'], ['Dr']) |
172 | 174 | ->expectsOutput('I will refer to you Dr Jane.'); |
173 | 175 | } |
174 | 176 |
|
@@ -231,4 +233,74 @@ public function handle() |
231 | 233 | ->expectsChoice('Which names do you like?', ['None'], ['John', 'Jane', 'Sally', 'Jack']) |
232 | 234 | ->expectsOutput('You like nobody.'); |
233 | 235 | } |
| 236 | + |
| 237 | + public function testAssertionForSearchPrompt() |
| 238 | + { |
| 239 | + $this->app[Kernel::class]->registerCommand( |
| 240 | + new class extends Command |
| 241 | + { |
| 242 | + protected $signature = 'test:search'; |
| 243 | + |
| 244 | + public function handle() |
| 245 | + { |
| 246 | + $options = collect(['John', 'Jane', 'Sally', 'Jack']); |
| 247 | + |
| 248 | + $name = search( |
| 249 | + label: 'What is your name?', |
| 250 | + options: fn (string $value) => strlen($value) > 0 |
| 251 | + ? $options->filter(fn ($title) => str_contains($title, $value))->values()->toArray() |
| 252 | + : [] |
| 253 | + ); |
| 254 | + |
| 255 | + $this->line("Your name is $name."); |
| 256 | + } |
| 257 | + } |
| 258 | + ); |
| 259 | + |
| 260 | + $this |
| 261 | + ->artisan('test:search') |
| 262 | + ->expectsQuestion('What is your name?', 'J') |
| 263 | + ->expectsChoice('What is your name?', 'Jane', ['John', 'Jane', 'Jack']) |
| 264 | + ->expectsOutput('Your name is Jane.'); |
| 265 | + } |
| 266 | + |
| 267 | + public function testAssertionForMultisearchPrompt() |
| 268 | + { |
| 269 | + $this->app[Kernel::class]->registerCommand( |
| 270 | + new class extends Command |
| 271 | + { |
| 272 | + protected $signature = 'test:multisearch'; |
| 273 | + |
| 274 | + public function handle() |
| 275 | + { |
| 276 | + $options = collect(['John', 'Jane', 'Sally', 'Jack']); |
| 277 | + |
| 278 | + $names = multisearch( |
| 279 | + label: 'Which names do you like?', |
| 280 | + options: fn (string $value) => strlen($value) > 0 |
| 281 | + ? $options->filter(fn ($title) => str_contains($title, $value))->values()->toArray() |
| 282 | + : [] |
| 283 | + ); |
| 284 | + |
| 285 | + if (empty($names)) { |
| 286 | + $this->line('You like nobody.'); |
| 287 | + } else { |
| 288 | + $this->line(sprintf('You like %s.', implode(', ', $names))); |
| 289 | + } |
| 290 | + } |
| 291 | + } |
| 292 | + ); |
| 293 | + |
| 294 | + $this |
| 295 | + ->artisan('test:multisearch') |
| 296 | + ->expectsQuestion('Which names do you like?', 'J') |
| 297 | + ->expectsChoice('Which names do you like?', ['John', 'Jane'], ['John', 'Jane', 'Jack']) |
| 298 | + ->expectsOutput('You like John, Jane.'); |
| 299 | + |
| 300 | + $this |
| 301 | + ->artisan('test:multisearch') |
| 302 | + ->expectsQuestion('Which names do you like?', 'J') |
| 303 | + ->expectsChoice('Which names do you like?', ['None'], ['John', 'Jane', 'Jack']) |
| 304 | + ->expectsOutput('You like nobody.'); |
| 305 | + } |
234 | 306 | } |
0 commit comments