AllowedValueSubsetTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\FixerConfiguration;
  13. use PhpCsFixer\FixerConfiguration\AllowedValueSubset;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\FixerConfiguration\AllowedValueSubset
  19. */
  20. final class AllowedValueSubsetTest extends TestCase
  21. {
  22. public static function provideGetAllowedValuesAreSortedCases(): iterable
  23. {
  24. yield [
  25. ['bar', 'foo'],
  26. ['foo', 'bar'],
  27. ];
  28. yield [
  29. ['bar', 'Foo'],
  30. ['Foo', 'bar'],
  31. ];
  32. }
  33. /**
  34. * @param list<string> $expected
  35. * @param list<string> $input
  36. *
  37. * @dataProvider provideGetAllowedValuesAreSortedCases
  38. */
  39. public function testGetAllowedValuesAreSorted(array $expected, array $input): void
  40. {
  41. $subset = new AllowedValueSubset($input);
  42. self::assertSame($expected, $subset->getAllowedValues());
  43. }
  44. /**
  45. * @param mixed $inputValue
  46. *
  47. * @dataProvider provideInvokeCases
  48. */
  49. public function testInvoke($inputValue, bool $expectedResult): void
  50. {
  51. $subset = new AllowedValueSubset(['foo', 'bar']);
  52. self::assertSame($expectedResult, $subset($inputValue));
  53. }
  54. public static function provideInvokeCases(): iterable
  55. {
  56. yield [
  57. ['foo', 'bar'],
  58. true,
  59. ];
  60. yield [
  61. ['bar', 'foo'],
  62. true,
  63. ];
  64. yield [
  65. ['foo'],
  66. true,
  67. ];
  68. yield [
  69. ['bar'],
  70. true,
  71. ];
  72. yield [
  73. [],
  74. true,
  75. ];
  76. yield [
  77. ['foo', 'bar', 'baz'],
  78. false,
  79. ];
  80. yield [
  81. ['baz'],
  82. false,
  83. ];
  84. yield [
  85. 1,
  86. false,
  87. ];
  88. yield [
  89. 1.2,
  90. false,
  91. ];
  92. yield [
  93. 'foo',
  94. false,
  95. ];
  96. yield [
  97. new \stdClass(),
  98. false,
  99. ];
  100. yield [
  101. true,
  102. false,
  103. ];
  104. yield [
  105. null,
  106. false,
  107. ];
  108. }
  109. public function testGetAllowedValues(): void
  110. {
  111. $values = ['bar', 'foo'];
  112. $subset = new AllowedValueSubset($values);
  113. self::assertSame($values, $subset->getAllowedValues());
  114. }
  115. }