|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Console\Tests\Question; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Console\Question\ChoiceQuestion; |
| 16 | + |
| 17 | +class ChoiceQuestionTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @dataProvider selectUseCases |
| 21 | + */ |
| 22 | + public function testSelectUseCases($multiSelect, $answers, $expected, $message) |
| 23 | + { |
| 24 | + $question = new ChoiceQuestion('A question', [ |
| 25 | + 'First response', |
| 26 | + 'Second response', |
| 27 | + 'Third response', |
| 28 | + 'Fourth response', |
| 29 | + ]); |
| 30 | + |
| 31 | + $question->setMultiselect($multiSelect); |
| 32 | + |
| 33 | + foreach ($answers as $answer) { |
| 34 | + $validator = $question->getValidator(); |
| 35 | + $actual = $validator($answer); |
| 36 | + |
| 37 | + $this->assertEquals($actual, $expected, $message); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public function selectUseCases() |
| 42 | + { |
| 43 | + return [ |
| 44 | + [ |
| 45 | + false, |
| 46 | + ['First response', 'First response ', ' First response', ' First response '], |
| 47 | + 'First response', |
| 48 | + 'When passed single answer on singleSelect, the defaultValidator must return this answer as a string', |
| 49 | + ], |
| 50 | + [ |
| 51 | + true, |
| 52 | + ['First response', 'First response ', ' First response', ' First response '], |
| 53 | + ['First response'], |
| 54 | + 'When passed single answer on MultiSelect, the defaultValidator must return this answer as an array', |
| 55 | + ], |
| 56 | + [ |
| 57 | + true, |
| 58 | + ['First response,Second response', ' First response , Second response '], |
| 59 | + ['First response', 'Second response'], |
| 60 | + 'When passed multiple answers on MultiSelect, the defaultValidator must return these answers as an array', |
| 61 | + ], |
| 62 | + ]; |
| 63 | + } |
| 64 | +} |
0 commit comments