LowercaseConstantsFixerTest.php 4.2 KB

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