NativeFunctionCasingFixerTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer
  18. *
  19. * @extends AbstractFixerTestCase<\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. /**
  31. * @return iterable<array{0: string, 1?: string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield [
  36. '<?php
  37. namespace Bar {
  38. function STRLEN($str) {
  39. return "overridden" . \strlen($str);
  40. }
  41. }
  42. namespace {
  43. echo \Bar\STRLEN("xxx");
  44. }',
  45. ];
  46. yield [
  47. '<?php
  48. echo strtolower("hello 1");
  49. ',
  50. '<?php
  51. echo STRTOLOWER("hello 1");
  52. ',
  53. ];
  54. yield [
  55. '<?php
  56. echo strtolower //a
  57. ("hello 2");
  58. ',
  59. '<?php
  60. echo STRTOLOWER //a
  61. ("hello 2");
  62. ',
  63. ];
  64. yield [
  65. '<?php
  66. echo strtolower /**/ ("hello 3");
  67. ',
  68. '<?php
  69. echo STRTOLOWER /**/ ("hello 3");
  70. ',
  71. ];
  72. yield [
  73. '<?php
  74. echo \sqrt(4);
  75. ',
  76. '<?php
  77. echo \sQrT(4);
  78. ',
  79. ];
  80. yield [
  81. '<?php
  82. echo "1".\sqrt("hello 5");
  83. ',
  84. '<?php
  85. echo "1".\SQRT("hello 5");
  86. ',
  87. ];
  88. yield [
  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. yield [
  105. '<?php
  106. new STRTOLOWER();
  107. ',
  108. ];
  109. yield [
  110. '<?php
  111. new \STRTOLOWER();
  112. ',
  113. ];
  114. yield [
  115. '<?php
  116. new \A\B\STRTOLOWER();
  117. ',
  118. ];
  119. yield [
  120. '<?php
  121. a::STRTOLOWER();
  122. ',
  123. ];
  124. yield [
  125. '<?php
  126. $a->STRTOLOWER();
  127. ',
  128. ];
  129. yield [
  130. '<?php fOoO();',
  131. ];
  132. yield [
  133. '<?php
  134. namespace Foo {
  135. function &Next() {
  136. return prev(-1);
  137. }
  138. }',
  139. ];
  140. yield [
  141. '<?php
  142. $next1 = & next($array1);
  143. $next2 = & \next($array2);
  144. ',
  145. '<?php
  146. $next1 = & Next($array1);
  147. $next2 = & \Next($array2);
  148. ',
  149. ];
  150. yield [
  151. '<?php
  152. namespace Foo;
  153. use function MyStuff\StrToLower;
  154. class Bar {
  155. public function getName() {
  156. return StrToLower($this->name);
  157. }
  158. }',
  159. ];
  160. yield [
  161. '<?php
  162. echo \sqrt(4 , );
  163. ',
  164. '<?php
  165. echo \sQrT(4 , );
  166. ',
  167. ];
  168. yield [
  169. '<?php
  170. $a->STRTOLOWER(1,);
  171. ',
  172. ];
  173. }
  174. /**
  175. * @dataProvider provideFix80Cases
  176. *
  177. * @requires PHP 8.0
  178. */
  179. public function testFix80(string $expected): void
  180. {
  181. $this->doTest($expected);
  182. }
  183. /**
  184. * @return iterable<array{string}>
  185. */
  186. public static function provideFix80Cases(): iterable
  187. {
  188. yield ['<?php $a?->STRTOLOWER(1,);'];
  189. yield [
  190. '<?php
  191. final class SomeClass
  192. {
  193. #[File(mimeTypes: ["application/pdf", "image/*"])]
  194. public FileBlob $attachment;
  195. }
  196. ',
  197. ];
  198. }
  199. }