LowercaseKeywordsFixerTest.php 3.2 KB

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