-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #32503 Fix multiSelect ChoiceQuestion when answers have spaces (I…
…ceMaD) This PR was merged into the 3.4 branch. Discussion ---------- Fix multiSelect ChoiceQuestion when answers have spaces | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32502 | License | MIT | Doc PR | N/A Probleme is explained in the issue Commits ------- 9104ef1 Fix multiSelect ChoiceQuestion when answers have spaces
- Loading branch information
Showing
2 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
64 changes: 64 additions & 0 deletions
64
src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Tests\Question; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
|
||
class ChoiceQuestionTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider selectUseCases | ||
*/ | ||
public function testSelectUseCases($multiSelect, $answers, $expected, $message) | ||
{ | ||
$question = new ChoiceQuestion('A question', [ | ||
'First response', | ||
'Second response', | ||
'Third response', | ||
'Fourth response', | ||
]); | ||
|
||
$question->setMultiselect($multiSelect); | ||
|
||
foreach ($answers as $answer) { | ||
$validator = $question->getValidator(); | ||
$actual = $validator($answer); | ||
|
||
$this->assertEquals($actual, $expected, $message); | ||
} | ||
} | ||
|
||
public function selectUseCases() | ||
{ | ||
return [ | ||
[ | ||
false, | ||
['First response', 'First response ', ' First response', ' First response '], | ||
'First response', | ||
'When passed single answer on singleSelect, the defaultValidator must return this answer as a string', | ||
], | ||
[ | ||
true, | ||
['First response', 'First response ', ' First response', ' First response '], | ||
['First response'], | ||
'When passed single answer on MultiSelect, the defaultValidator must return this answer as an array', | ||
], | ||
[ | ||
true, | ||
['First response,Second response', ' First response , Second response '], | ||
['First response', 'Second response'], | ||
'When passed multiple answers on MultiSelect, the defaultValidator must return these answers as an array', | ||
], | ||
]; | ||
} | ||
} |