ImplodeCallFixerTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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\FunctionNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Kuba Werłos <werlos@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\FunctionNotation\ImplodeCallFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\FunctionNotation\ImplodeCallFixer>
  22. */
  23. final class ImplodeCallFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield ["<?php implode('', [1,2,3]);"];
  38. yield ['<?php implode("", $foo);'];
  39. yield ['<?php implode($foo, $bar);'];
  40. yield ['<?php $arrayHelper->implode($foo);'];
  41. yield ['<?php ArrayHelper::implode($foo);'];
  42. yield ['<?php ArrayHelper\implode($foo);'];
  43. yield ['<?php define("implode", "foo"); implode; bar($baz);'];
  44. yield [
  45. '<?php implode("", $foo);',
  46. '<?php implode($foo, "");',
  47. ];
  48. yield [
  49. '<?php \implode("", $foo);',
  50. '<?php \implode($foo, "");',
  51. ];
  52. yield [
  53. '<?php implode("Lorem ipsum dolor sit amet", $foo);',
  54. '<?php implode($foo, "Lorem ipsum dolor sit amet");',
  55. ];
  56. yield [
  57. '<?php implode(\'\', $foo);',
  58. '<?php implode($foo);',
  59. ];
  60. yield [
  61. '<?php IMPlode("", $foo);',
  62. '<?php IMPlode($foo, "");',
  63. ];
  64. yield [
  65. '<?php implode("",$foo);',
  66. '<?php implode($foo,"");',
  67. ];
  68. yield [
  69. '<?php implode("", $weirdStuff[mt_rand($min, getMax()) + 200]);',
  70. '<?php implode($weirdStuff[mt_rand($min, getMax()) + 200], "");',
  71. ];
  72. yield [
  73. '<?php
  74. implode(
  75. "",
  76. $foo
  77. );',
  78. '<?php
  79. implode(
  80. $foo,
  81. ""
  82. );',
  83. ];
  84. yield [
  85. '<?php
  86. implode(
  87. \'\', $foo
  88. );',
  89. '<?php
  90. implode(
  91. $foo
  92. );',
  93. ];
  94. yield [
  95. '<?php
  96. implode(# 1
  97. ""/* 2.1 */,# 2.2
  98. $foo# 3
  99. );',
  100. '<?php
  101. implode(# 1
  102. $foo/* 2.1 */,# 2.2
  103. ""# 3
  104. );',
  105. ];
  106. yield [
  107. '<?php
  108. implode(# 1
  109. # 2
  110. \'\', $foo# 3
  111. # 4
  112. )# 5
  113. ;',
  114. '<?php
  115. implode(# 1
  116. # 2
  117. $foo# 3
  118. # 4
  119. )# 5
  120. ;',
  121. ];
  122. yield [
  123. '<?php
  124. implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);
  125. // comment for testing
  126. implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);implode(\'\', $a);
  127. ',
  128. '<?php
  129. implode($a);implode($a);implode($a);implode($a);implode($a);implode($a);
  130. // comment for testing
  131. implode($a);implode($a);implode($a);implode($a);implode($a);implode($a);
  132. ',
  133. ];
  134. yield [
  135. '<?php implode("", $foo, );',
  136. '<?php implode($foo, "", );',
  137. ];
  138. yield [
  139. '<?php implode(\'\', $foo, );',
  140. '<?php implode($foo, );',
  141. ];
  142. yield [
  143. '<?php
  144. implode(
  145. "",
  146. $foo,
  147. );',
  148. '<?php
  149. implode(
  150. $foo,
  151. "",
  152. );',
  153. ];
  154. }
  155. }