NativeFunctionCasingFixerTest.php 4.5 KB

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