ChoiceQuestionTest.php 2.0 KB

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