This PR adds a new console test method for asking choices
.
You can ask a multiple-choice question in a Laravel command with the choice
method:
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], $defaultIndex);
Currently, you can only assert
the message
of this question and define a reply like:
$this->artisan('question')
->expectsQuestion('What is your name?', 'Taylor Otwell')
->assertExitCode(0);
}
What you cannot test
here are the given choices: ['Taylor', 'Dayle']
Depending on how your command looks like, these choices may change through input.
In order to solve this problem, this PR adds a new method to expect choices. The code above can now be tested like:
$this->artisan('question')
->expectsChoice('What is your name?', 'Taylor Otwell', ['Taylor', 'Dayle'])
->assertExitCode(0);
}
Next to the message and the reply, you can now define the expected choices as well.