Skip to content
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] Fix expectsChoice assertion with optional multiselect prompts. #51078

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

jessarcher
Copy link
Member

This PR fixes the issue raised in #51056, where expectsChoice couldn't easily be used with a multiselect prompt with required: 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 in PromptOption 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 the isAssoc method on the ChoiceQuestion 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.

@taylorotwell taylorotwell merged commit f57756a into 11.x Apr 16, 2024
29 checks passed
@taylorotwell taylorotwell deleted the prompt-fallback-fixes branch April 16, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants