AllowedValueSubsetTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. self::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. self::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. self::assertSame($expectedResult, $subset($inputValue));
  57. }
  58. public static function provideInvokeCases(): iterable
  59. {
  60. yield [
  61. ['foo', 'bar'],
  62. true,
  63. ];
  64. yield [
  65. ['bar', 'foo'],
  66. true,
  67. ];
  68. yield [
  69. ['foo'],
  70. true,
  71. ];
  72. yield [
  73. ['bar'],
  74. true,
  75. ];
  76. yield [
  77. [],
  78. true,
  79. ];
  80. yield [
  81. ['foo', 'bar', 'baz'],
  82. false,
  83. ];
  84. yield [
  85. ['baz'],
  86. false,
  87. ];
  88. yield [
  89. 1,
  90. false,
  91. ];
  92. yield [
  93. 1.2,
  94. false,
  95. ];
  96. yield [
  97. 'foo',
  98. false,
  99. ];
  100. yield [
  101. new \stdClass(),
  102. false,
  103. ];
  104. yield [
  105. true,
  106. false,
  107. ];
  108. yield [
  109. null,
  110. false,
  111. ];
  112. }
  113. public function testGetAllowedValues(): void
  114. {
  115. $values = ['bar', 'foo'];
  116. $subset = new AllowedValueSubset($values);
  117. self::assertSame($values, $subset->getAllowedValues());
  118. }
  119. }