AllowedValueSubsetTest.php 2.9 KB

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