LowercaseConstantsFixerTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\Casing;
  12. use PhpCsFixer\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. * @author SpacePossum
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Casing\LowercaseConstantsFixer
  20. */
  21. final class LowercaseConstantsFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @param string $expected
  25. * @param null|string $input
  26. *
  27. * @dataProvider provideGeneratedCases
  28. */
  29. public function testFixGeneratedCases($expected, $input = null)
  30. {
  31. $this->doTest($expected, $input);
  32. }
  33. public function provideGeneratedCases()
  34. {
  35. $cases = [];
  36. foreach (['true', 'false', 'null'] as $case) {
  37. $cases[] = [
  38. sprintf('<?php $x = %s;', $case),
  39. sprintf('<?php $x = %s;', strtoupper($case)),
  40. ];
  41. $cases[] = [
  42. sprintf('<?php $x = %s;', $case),
  43. sprintf('<?php $x = %s;', ucfirst($case)),
  44. ];
  45. $cases[] = [sprintf('<?php $x = new %s;', ucfirst($case))];
  46. $cases[] = [sprintf('<?php $x = new %s;', strtoupper($case))];
  47. $cases[] = [sprintf('<?php $x = "%s story";', $case)];
  48. $cases[] = [sprintf('<?php $x = "%s";', $case)];
  49. }
  50. return $cases;
  51. }
  52. /**
  53. * @param string $expected
  54. * @param null|string $input
  55. *
  56. * @dataProvider provideCases
  57. */
  58. public function testFix($expected, $input = null)
  59. {
  60. $this->doTest($expected, $input);
  61. }
  62. public function provideCases()
  63. {
  64. return [
  65. [
  66. '<?php if (true) if (false) if (null) {}',
  67. '<?php if (TRUE) if (FALSE) if (NULL) {}',
  68. ],
  69. [
  70. '<?php if (!true) if (!false) if (!null) {}',
  71. '<?php if (!TRUE) if (!FALSE) if (!NULL) {}',
  72. ],
  73. [
  74. '<?php if ($a == true) if ($a == false) if ($a == null) {}',
  75. '<?php if ($a == TRUE) if ($a == FALSE) if ($a == NULL) {}',
  76. ],
  77. [
  78. '<?php if ($a === true) if ($a === false) if ($a === null) {}',
  79. '<?php if ($a === TRUE) if ($a === FALSE) if ($a === NULL) {}',
  80. ],
  81. [
  82. '<?php if ($a != true) if ($a != false) if ($a != null) {}',
  83. '<?php if ($a != TRUE) if ($a != FALSE) if ($a != NULL) {}',
  84. ],
  85. [
  86. '<?php if ($a !== true) if ($a !== false) if ($a !== null) {}',
  87. '<?php if ($a !== TRUE) if ($a !== FALSE) if ($a !== NULL) {}',
  88. ],
  89. [
  90. '<?php if (true && true and true AND true || false or false OR false xor null XOR null) {}',
  91. '<?php if (TRUE && TRUE and TRUE AND TRUE || FALSE or FALSE OR FALSE xor NULL XOR NULL) {}',
  92. ],
  93. [
  94. '<?php /* foo */ true; /** bar */ false;',
  95. '<?php /* foo */ TRUE; /** bar */ FALSE;',
  96. ],
  97. ['<?php echo $null;'],
  98. ['<?php $x = False::foo();'],
  99. ['<?php namespace Foo\Null;'],
  100. ['<?php use Foo\Null;'],
  101. ['<?php use Foo\Null as Null;'],
  102. ['<?php class True {} class False {} class Null {}'],
  103. ['<?php class Foo extends True {}'],
  104. ['<?php class Foo implements False {}'],
  105. ['<?php Class Null { use True; }'],
  106. ['<?php interface True {}'],
  107. ['<?php $foo instanceof True; $foo instanceof False; $foo instanceof Null;'],
  108. [
  109. '<?php
  110. class Foo
  111. {
  112. const TRUE = 1;
  113. const FALSE = 2;
  114. const NULL = null;
  115. }',
  116. ],
  117. ['<?php $x = new /**/False?>'],
  118. ['<?php Null/**/::test();'],
  119. ['<?php True//
  120. ::test();'],
  121. ['<?php trait False {}'],
  122. [
  123. '<?php
  124. class Null {
  125. use True, False {
  126. False::bar insteadof True;
  127. True::baz insteadof False;
  128. False::baz as Null;
  129. }
  130. }',
  131. ],
  132. ];
  133. }
  134. }