diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index 723895b7ef85..1d71cf578674 100644 --- a/src/Illuminate/Testing/PendingCommand.php +++ b/src/Illuminate/Testing/PendingCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; +use Symfony\Component\Console\Question\ChoiceQuestion; class PendingCommand { @@ -397,7 +398,9 @@ protected function mockConsoleOutput() ->ordered() ->with(Mockery::on(function ($argument) use ($question) { if (isset($this->test->expectedChoices[$question[0]])) { - $this->test->expectedChoices[$question[0]]['actual'] = $argument->getAutocompleterValues(); + $this->test->expectedChoices[$question[0]]['actual'] = $argument instanceof ChoiceQuestion && ! array_is_list($this->test->expectedChoices[$question[0]]['expected']) + ? $argument->getChoices() + : $argument->getAutocompleterValues(); } return $argument->getQuestion() == $question[0]; diff --git a/tests/Integration/Console/PromptsAssertionTest.php b/tests/Integration/Console/PromptsAssertionTest.php index 2bec3a2340e7..6822be83fc0d 100644 --- a/tests/Integration/Console/PromptsAssertionTest.php +++ b/tests/Integration/Console/PromptsAssertionTest.php @@ -10,6 +10,7 @@ use function Laravel\Prompts\multiselect; use function Laravel\Prompts\password; use function Laravel\Prompts\select; +use function Laravel\Prompts\suggest; use function Laravel\Prompts\text; use function Laravel\Prompts\textarea; @@ -59,6 +60,28 @@ public function handle() ->expectsOutput('Jane'); } + public function testAssertionForSuggestPrompt() + { + $this->app[Kernel::class]->registerCommand( + new class extends Command + { + protected $signature = 'test:suggest'; + + public function handle() + { + $name = suggest('What is your name?', ['John', 'Jane']); + + $this->line($name); + } + } + ); + + $this + ->artisan('test:suggest') + ->expectsChoice('What is your name?', 'Joe', ['John', 'Jane']) + ->expectsOutput('Joe'); + } + public function testAssertionForPasswordPrompt() { $this->app[Kernel::class]->registerCommand( @@ -112,7 +135,7 @@ public function handle() ->expectsOutput('Your name is John.'); } - public function testAssertionForSelectPrompt() + public function testAssertionForSelectPromptWithAList() { $this->app[Kernel::class]->registerCommand( new class extends Command @@ -137,6 +160,56 @@ public function handle() ->expectsOutput('Your name is Jane.'); } + public function testAssertionForSelectPromptWithAnAssociativeArray() + { + $this->app[Kernel::class]->registerCommand( + new class extends Command + { + protected $signature = 'test:select'; + + public function handle() + { + $name = select( + label: 'What is your name?', + options: ['john' => 'John', 'jane' => 'Jane'] + ); + + $this->line("Your name is $name."); + } + } + ); + + $this + ->artisan('test:select') + ->expectsChoice('What is your name?', 'jane', ['john' => 'John', 'jane' => 'Jane']) + ->expectsOutput('Your name is jane.'); + } + + public function testAlternativeAssertionForSelectPromptWithAnAssociativeArray() + { + $this->app[Kernel::class]->registerCommand( + new class extends Command + { + protected $signature = 'test:select'; + + public function handle() + { + $name = select( + label: 'What is your name?', + options: ['john' => 'John', 'jane' => 'Jane'] + ); + + $this->line("Your name is $name."); + } + } + ); + + $this + ->artisan('test:select') + ->expectsChoice('What is your name?', 'jane', ['john', 'jane', 'John', 'Jane']) + ->expectsOutput('Your name is jane.'); + } + public function testAssertionForRequiredMultiselectPrompt() { $this->app[Kernel::class]->registerCommand(