LowercaseKeywordsFixerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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\Fixer\Casing;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer
  20. */
  21. final class LowercaseKeywordsFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. return [
  33. ['<?php $x = (1 and 2);', '<?php $x = (1 AND 2);'],
  34. ['<?php foreach(array(1, 2, 3) as $val) {}', '<?php FOREACH(array(1, 2, 3) AS $val) {}'],
  35. ['<?php echo "GOOD AS NEW";'],
  36. ['<?php echo X::class ?>', '<?php echo X::ClASs ?>'],
  37. [
  38. '<?php $fn = fn() => true;',
  39. '<?php $fn = FN() => true;',
  40. ],
  41. ];
  42. }
  43. public function testHaltCompiler(): void
  44. {
  45. $this->doTest('<?php __HALT_COMPILER();');
  46. }
  47. /**
  48. * @dataProvider provideFix80Cases
  49. *
  50. * @requires PHP 8.0
  51. */
  52. public function testFix80(string $expected, string $input): void
  53. {
  54. $this->doTest($expected, $input);
  55. }
  56. public static function provideFix80Cases(): iterable
  57. {
  58. yield [
  59. '<?php
  60. echo match (1) {
  61. 1 => 9,
  62. 2 => 7,
  63. };',
  64. '<?php
  65. echo MATCH (1) {
  66. 1 => 9,
  67. 2 => 7,
  68. };',
  69. ];
  70. yield [
  71. '<?php
  72. class Point {
  73. public function __construct(
  74. public float $x = 0.0,
  75. protected float $y = 0.0,
  76. private float $z = 0.0,
  77. ) {}
  78. }
  79. ',
  80. '<?php
  81. class Point {
  82. public function __construct(
  83. PUBLIC float $x = 0.0,
  84. Protected float $y = 0.0,
  85. privatE float $z = 0.0,
  86. ) {}
  87. }
  88. ',
  89. ];
  90. }
  91. /**
  92. * @dataProvider provideFix81Cases
  93. *
  94. * @requires PHP 8.1
  95. */
  96. public function testFix81(string $expected, string $input): void
  97. {
  98. $this->doTest($expected, $input);
  99. }
  100. public static function provideFix81Cases(): iterable
  101. {
  102. yield [
  103. '<?php
  104. final class Foo
  105. {
  106. public readonly string $prop;
  107. }
  108. ',
  109. '<?php
  110. final class Foo
  111. {
  112. public READONLY string $prop;
  113. }
  114. ',
  115. ];
  116. yield [
  117. '<?php
  118. class Point {
  119. public function __construct(
  120. public readonly float $x = 0.0,
  121. readonly protected float $y = 0.0,
  122. private readonly float $z = 0.0,
  123. ) {}
  124. }
  125. ',
  126. '<?php
  127. class Point {
  128. public function __construct(
  129. PUBLIC rEADONLY float $x = 0.0,
  130. READonly Protected float $y = 0.0,
  131. privatE READONLY float $z = 0.0,
  132. ) {}
  133. }
  134. ',
  135. ];
  136. yield 'enum full caps' => [
  137. '<?php
  138. enum Suit {
  139. case Hearts;
  140. }
  141. ',
  142. '<?php
  143. ENUM Suit {
  144. case Hearts;
  145. }
  146. ',
  147. ];
  148. }
  149. }