MbStrFunctionsFixerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Alias;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Filippo Tessarotto <zoeslam@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\AbstractFunctionReferenceFixer
  20. * @covers \PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer
  21. */
  22. final class MbStrFunctionsFixerTest extends AbstractFixerTestCase
  23. {
  24. /**
  25. * @dataProvider provideFixCases
  26. */
  27. public function testFix(string $expected, ?string $input = null): void
  28. {
  29. $this->doTest($expected, $input);
  30. }
  31. public static function provideFixCases(): iterable
  32. {
  33. return [
  34. ['<?php $x = "strlen";'],
  35. ['<?php $x = Foo::strlen("bar");'],
  36. ['<?php $x = new strlen("bar");'],
  37. ['<?php $x = new \strlen("bar");'],
  38. ['<?php $x = new Foo\strlen("bar");'],
  39. ['<?php $x = Foo\strlen("bar");'],
  40. ['<?php $x = strlen::call("bar");'],
  41. ['<?php $x = $foo->strlen("bar");'],
  42. ['<?php $x = strlen();'], // number of arguments mismatch
  43. ['<?php $x = strlen($a, $b);'], // number of arguments mismatch
  44. ['<?php $x = mb_strlen("bar");', '<?php $x = strlen("bar");'],
  45. ['<?php $x = \mb_strlen("bar");', '<?php $x = \strlen("bar");'],
  46. ['<?php $x = mb_strtolower(mb_strstr("bar", "a"));', '<?php $x = strtolower(strstr("bar", "a"));'],
  47. ['<?php $x = mb_strtolower( \mb_strstr ("bar", "a"));', '<?php $x = strtolower( \strstr ("bar", "a"));'],
  48. ['<?php $x = mb_substr("bar", 2, 1);', '<?php $x = substr("bar", 2, 1);'],
  49. [
  50. '<?php
  51. interface Test
  52. {
  53. public function &strlen($a);
  54. public function strtolower($a);
  55. }',
  56. ],
  57. [
  58. '<?php $a = mb_str_split($a);',
  59. '<?php $a = str_split($a);',
  60. ],
  61. ];
  62. }
  63. }