ConfirmationQuestionTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\ConfirmationQuestion;
  13. class ConfirmationQuestionTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider normalizerUsecases
  17. */
  18. public function testDefaultRegexUsecases($default, $answers, $expected, $message)
  19. {
  20. $sut = new ConfirmationQuestion('A question', $default);
  21. foreach ($answers as $answer) {
  22. $normalizer = $sut->getNormalizer();
  23. $actual = $normalizer($answer);
  24. $this->assertEquals($expected, $actual, sprintf($message, $answer));
  25. }
  26. }
  27. public function normalizerUsecases()
  28. {
  29. return [
  30. [
  31. true,
  32. ['y', 'Y', 'yes', 'YES', 'yEs', ''],
  33. true,
  34. 'When default is true, the normalizer must return true for "%s"',
  35. ],
  36. [
  37. true,
  38. ['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0'],
  39. false,
  40. 'When default is true, the normalizer must return false for "%s"',
  41. ],
  42. [
  43. false,
  44. ['y', 'Y', 'yes', 'YES', 'yEs'],
  45. true,
  46. 'When default is false, the normalizer must return true for "%s"',
  47. ],
  48. [
  49. false,
  50. ['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0', ''],
  51. false,
  52. 'When default is false, the normalizer must return false for "%s"',
  53. ],
  54. ];
  55. }
  56. }