-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] - Allow Prompt's multiselect
prompt to be tested using expectsChoice
#51056
[11.x] - Allow Prompt's multiselect
prompt to be tested using expectsChoice
#51056
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
Hey @lioneaglesolutions, thanks for the PR!
The 'None' option is required because the The fallbacks serve two purposes:
The 'None' option really only serves the first purpose, allowing Windows users to select 0 options. The I think a short-term solution would be to not inject the 'None' option (and maybe not even use the I think a longer-term solution would be to build test assertions into the Prompts library itself so that Symfony is only used for the Windows fallbacks. |
Hey @lioneaglesolutions, I've created #51078, which should solve this issue 👍 |
Thanks @jessarcher good to see it fix - loved this |
Dependent on another PR
This PR depends on #51055 and should not be merged until it is merged.
Purpose
This PR will allow the
expectsChoice
method to be used when a Laravel Promptmultiselect
is being used but whenrequired
isfalse
.Failing Test
I'm not quire sure how to approach the fix here so I first created a failing test;
https://github.com/laravel/framework/pull/51056/files#diff-2cba8279071f67c5fee6df1c8f5112974a28f48ef91fe0e821193ed27c6d8e1cR95-R101
Issue
The issue has to do with the fact that an additional option is being added when
required === false
;framework/src/Illuminate/Console/Concerns/ConfiguresPrompts.php
Lines 247 to 253 in 48246da
Then, ALL options are being passed to the
choice
component;framework/src/Illuminate/Console/Concerns/ConfiguresPrompts.php
Line 259 in 48246da
The
expectsChoice
assertion though does not cater for the additional choice that has been added. I assume this is because theexpectsChoice
method is interacting directly with the Symfony command that handlesrequired
internally on it's own.Proposed Solutions
I'm unsure how to best handle this because I'm not sure why
$options = [new PromptOption(null, 'None'), ...$options];
is required in the first place.I was hoping @jessarcher could provide some insights as to how I could go about fixing this failing test.
Adjusting the expectation
If we add
None
to the expection, this makes the test pass but won't work if the user has actually definedNone
as an option in their arg list as well;Extract prompt options
This is what I initially tried in this PR but tests were then failing...