HelpCommandTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Console\Command;
  13. use PhpCsFixer\Console\Command\HelpCommand;
  14. use PhpCsFixer\FixerConfiguration\FixerOption;
  15. use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
  16. use PhpCsFixer\Tests\TestCase;
  17. /**
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Console\Command\HelpCommand
  21. */
  22. final class HelpCommandTest extends TestCase
  23. {
  24. /**
  25. * @param mixed $input
  26. *
  27. * @dataProvider provideToStringCases
  28. */
  29. public function testToString(string $expected, $input): void
  30. {
  31. static::assertSame($expected, HelpCommand::toString($input));
  32. }
  33. public function provideToStringCases(): \Generator
  34. {
  35. yield ["['a' => 3, 'b' => 'c']", ['a' => 3, 'b' => 'c']];
  36. yield ['[[1], [2]]', [[1], [2]]];
  37. yield ['[0 => [1], \'a\' => [2]]', [[1], 'a' => [2]]];
  38. yield ['[1, 2, \'foo\', null]', [1, 2, 'foo', null]];
  39. yield ['[1, 2]', [1, 2]];
  40. yield ['[]', []];
  41. yield ['1.5', 1.5];
  42. yield ['false', false];
  43. yield ['true', true];
  44. yield ['1', 1];
  45. yield ["'foo'", 'foo'];
  46. }
  47. /**
  48. * @param null|mixed $expected
  49. *
  50. * @dataProvider provideGetDisplayableAllowedValuesCases
  51. */
  52. public function testGetDisplayableAllowedValues($expected, FixerOptionInterface $input): void
  53. {
  54. static::assertSame($expected, HelpCommand::getDisplayableAllowedValues($input));
  55. }
  56. public function provideGetDisplayableAllowedValuesCases(): \Generator
  57. {
  58. yield [null, new FixerOption('foo', 'bar', false, null, ['int'], [])];
  59. yield [['A', 'B', 'x', 'z'], new FixerOption('foo', 'bar', false, null, ['string'], ['z', 'x', 'B', 'A'])];
  60. yield [[0, 3, 9], new FixerOption('foo', 'bar', false, null, ['int'], [0, 3, 9, static function (): void {}])];
  61. yield [null, new FixerOption('foo', 'bar')];
  62. }
  63. }