NativeFunctionCasingFixerTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author SpacePossum
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer
  19. */
  20. final class NativeFunctionCasingFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. public function provideFixCases()
  33. {
  34. return [
  35. [
  36. '<?php
  37. namespace Bar {
  38. function STRLEN($str) {
  39. return "overriden" . \strlen($str);
  40. }
  41. }
  42. namespace {
  43. echo \Bar\STRLEN("xxx");
  44. }',
  45. ],
  46. [
  47. '<?php
  48. echo strtolower("hello 1");
  49. ',
  50. '<?php
  51. echo STRTOLOWER("hello 1");
  52. ',
  53. ],
  54. [
  55. '<?php
  56. echo strtolower //a
  57. ("hello 2");
  58. ',
  59. '<?php
  60. echo STRTOLOWER //a
  61. ("hello 2");
  62. ',
  63. ],
  64. [
  65. '<?php
  66. echo strtolower /**/ ("hello 3");
  67. ',
  68. '<?php
  69. echo STRTOLOWER /**/ ("hello 3");
  70. ',
  71. ],
  72. [
  73. '<?php
  74. echo \sqrt(4);
  75. ',
  76. '<?php
  77. echo \sQrT(4);
  78. ',
  79. ],
  80. [
  81. '<?php
  82. echo "1".\sqrt("hello 5");
  83. ',
  84. '<?php
  85. echo "1".\SQRT("hello 5");
  86. ',
  87. ],
  88. [
  89. '<?php
  90. class Test{
  91. public function gettypE()
  92. {
  93. return 1;
  94. }
  95. function sqrT($a)
  96. {
  97. }
  98. function &END($a)
  99. {
  100. }
  101. }
  102. ',
  103. ],
  104. [
  105. '<?php
  106. new STRTOLOWER();
  107. ',
  108. ],
  109. [
  110. '<?php
  111. new \STRTOLOWER();
  112. ',
  113. ],
  114. [
  115. '<?php
  116. new \A\B\STRTOLOWER();
  117. ',
  118. ],
  119. [
  120. '<?php
  121. a::STRTOLOWER();
  122. ',
  123. ],
  124. [
  125. '<?php
  126. $a->STRTOLOWER();
  127. ',
  128. ],
  129. [
  130. '<?php fOoO();',
  131. ],
  132. [
  133. '<?php
  134. namespace Foo {
  135. function &Next() {
  136. return prev(-1);
  137. }
  138. }',
  139. ],
  140. [
  141. '<?php
  142. $next1 = & next($array1);
  143. $next2 = & \next($array2);
  144. ',
  145. '<?php
  146. $next1 = & Next($array1);
  147. $next2 = & \Next($array2);
  148. ',
  149. ],
  150. ];
  151. }
  152. /**
  153. * @param string $expected
  154. * @param null|string $input
  155. *
  156. * @requires PHP 7.3
  157. * @dataProvider provideFix73Cases
  158. */
  159. public function testFix73($expected, $input = null)
  160. {
  161. $this->doTest($expected, $input);
  162. }
  163. public function provideFix73Cases()
  164. {
  165. return [
  166. [
  167. '<?php
  168. echo \sqrt(4 , );
  169. ',
  170. '<?php
  171. echo \sQrT(4 , );
  172. ',
  173. ],
  174. [
  175. '<?php
  176. $a->STRTOLOWER(1,);
  177. ',
  178. ],
  179. ];
  180. }
  181. }