[11.x] Fix expectsChoice
assertion with optional multiselect
prompts.
#51078
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the issue raised in #51056, where
expectsChoice
couldn't easily be used with amultiselect
prompt withrequired: false
.The solution is to not inject the "None" option when running tests so that the test expectation matches the values passed to Symfony. The "None" behavior is unit-tested, so it doesn't need to be part of the application test suite.
It also fixes an issue introduced by #50995 where a failing
expectsChoice
assertion is hard to diagnose due to the options being wrapped inPromptOption
classes which don't get rendered as strings in the test output.The
PromptOption
class was introduced in #50995 to solve an issue where Symfony would return values when the array has all numeric keys, which differs from Prompts.This PR removes the
PromptOption
class and instead solves the key issue by overriding theisAssoc
method on theChoiceQuestion
class to match the behavior of Prompts.Finally, this PR also fixes another small inconsistency I noticed between Prompts and Symfony: Symfony returns numeric keys as strings, while Prompts returns them as integers.