[Console] Fix first choice was invalid when using value#14648
Merged
fabpot merged 1 commit intosymfony:2.7from May 20, 2015
ogizanagi:console_choices_2_7
Merged
[Console] Fix first choice was invalid when using value#14648fabpot merged 1 commit intosymfony:2.7from ogizanagi:console_choices_2_7
fabpot merged 1 commit intosymfony:2.7from
ogizanagi:console_choices_2_7
Conversation
Using question helper and choices questions: - first choice was not selectable by value. - ChoiceList with associative choices with mixed string and int keys has same issue with first choice. Add test for all choices. - Fix inconsistency by always returning values as strings
Member
|
Thank you @ogizanagi. |
fabpot
added a commit
that referenced
this pull request
May 20, 2015
…gizanagi) This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix first choice was invalid when using value | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR solves the following issues encountered using question helper and choices questions: - First choice was not selectable by value. - ChoiceList with associative choices with mixed string and int keys has same issue with first choice. - Fix inconsistency by always returning values as strings. First point exemple:  Last two points are mainly edge cases. Indeed, if a QuestionChoice has something like : ```php array( '0' => 'No environment', '1' => 'My environment 1', 'env_2' => 'My environment 2', 3 => 'My environment 3', ); ``` as choices, you will not be able to select the first choice and get an `InvalidArgumentException`: ``` There were 2 errors: 1) Symfony\Component\Console\Tests\Helper\QuestionHelperTest::testChoiceFromChoicelistWithMixedKeys with data set #0 ('0', '0') InvalidArgumentException: Value "0" is invalid 2) Symfony\Component\Console\Tests\Helper\QuestionHelperTest::testChoiceFromChoicelistWithMixedKeys with data set #1 ('No environment', '0') InvalidArgumentException: Value "No environment" is invalid ``` Moreover, even if you were able to select by value (`No environment`), you'll get an integer instead of a string: ``` Failed asserting that '0' is identical to 0. ``` For more consistency, the solution is to always return a string. The issue does not exist in 2.6, as the `QuestionChoice::getDefaultValidator` handled things differently. Commits ------- 03e4ab6 [Console] Fix first choice was invalid when using value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 solves the following issues encountered using question helper and choices questions:
First point exemple:

Last two points are mainly edge cases. Indeed, if a QuestionChoice has something like :
as choices, you will not be able to select the first choice and get an
InvalidArgumentException:Moreover, even if you were able to select by value (
No environment), you'll get an integer instead of a string:For more consistency, the solution is to always return a string.
The issue does not exist in 2.6, as the
QuestionChoice::getDefaultValidatorhandled things differently.