NoSpacesAfterFunctionNameFixerTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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\FunctionNotation;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Varga Bence <vbence@czentral.org>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\FunctionNotation\NoSpacesAfterFunctionNameFixer
  19. */
  20. final class NoSpacesAfterFunctionNameFixerTest 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. $tests = [
  35. 'test function call' => [
  36. '<?php abc($a);',
  37. '<?php abc ($a);',
  38. ],
  39. 'test method call' => [
  40. '<?php $o->abc($a);',
  41. '<?php $o->abc ($a);',
  42. ],
  43. 'test function-like constructs' => [
  44. '<?php
  45. include("something.php");
  46. include_once("something.php");
  47. require("something.php");
  48. require_once("something.php");
  49. print("hello");
  50. unset($hello);
  51. isset($hello);
  52. empty($hello);
  53. die($hello);
  54. echo("hello");
  55. array("hello");
  56. list($a, $b) = $c;
  57. eval("a");
  58. foo();
  59. $foo = &ref();
  60. ',
  61. '<?php
  62. include ("something.php");
  63. include_once ("something.php");
  64. require ("something.php");
  65. require_once ("something.php");
  66. print ("hello");
  67. unset ($hello);
  68. isset ($hello);
  69. empty ($hello);
  70. die ($hello);
  71. echo ("hello");
  72. array ("hello");
  73. list ($a, $b) = $c;
  74. eval ("a");
  75. foo ();
  76. $foo = &ref ();
  77. ',
  78. ],
  79. [
  80. '<?php echo foo(1) ? "y" : "n";',
  81. '<?php echo foo (1) ? "y" : "n";',
  82. ],
  83. [
  84. '<?php echo isset($name) ? "y" : "n";',
  85. '<?php echo isset ($name) ? "y" : "n";',
  86. ],
  87. [
  88. '<?php include (isHtml())? "1.html": "1.php";',
  89. '<?php include (isHtml ())? "1.html": "1.php";',
  90. ],
  91. // skip other language constructs
  92. [
  93. '<?php $a = 2 * (1 + 1);',
  94. ],
  95. [
  96. '<?php echo ($a == $b) ? "foo" : "bar";',
  97. ],
  98. [
  99. '<?php echo ($a == test($b)) ? "foo" : "bar";',
  100. ],
  101. [
  102. '<?php include ($html)? "custom.html": "custom.php";',
  103. ],
  104. 'don\'t touch function declarations' => [
  105. '<?php
  106. function TisMy ($p1)
  107. {
  108. print $p1;
  109. }
  110. ',
  111. ],
  112. [
  113. '<?php class A {
  114. function TisMy ($p1)
  115. {
  116. print $p1;
  117. }
  118. }',
  119. ],
  120. 'test dynamic by array' => [
  121. '<?php $a["e"](1); $a[2](1);',
  122. '<?php $a["e"] (1); $a[2] (1);',
  123. ],
  124. 'test variable variable' => [
  125. '<?php
  126. ${$e}(1);
  127. $$e(2);
  128. ',
  129. "<?php
  130. \${\$e}\t(1);
  131. \$\$e (2);
  132. ",
  133. ],
  134. 'test dynamic function and method calls' => [
  135. '<?php $b->$a(); $c();',
  136. '<?php $b->$a (); $c ();',
  137. ],
  138. 'test function call comment' => [
  139. '<?php abc#
  140. ($a);',
  141. ],
  142. ];
  143. foreach ($tests as $index => $test) {
  144. yield $index => $test;
  145. }
  146. if (\PHP_VERSION_ID < 80000) {
  147. yield 'test dynamic by array, curly mix' => [
  148. '<?php $a["e"](1); $a{2}(1);',
  149. '<?php $a["e"] (1); $a{2} (1);',
  150. ];
  151. yield 'test dynamic by array, curly only' => [
  152. '<?php $a{"e"}(1); $a{2}(1);',
  153. '<?php $a{"e"} (1); $a{2} (1);',
  154. ];
  155. }
  156. }
  157. /**
  158. * @param string $expected
  159. * @param null|string $input
  160. *
  161. * @dataProvider provideFix54Cases
  162. */
  163. public function test54($expected, $input = null)
  164. {
  165. $this->doTest($expected, $input);
  166. }
  167. public function provideFix54Cases()
  168. {
  169. return [
  170. [
  171. '<?php echo (new Process())->getOutput();',
  172. '<?php echo (new Process())->getOutput ();',
  173. ],
  174. ];
  175. }
  176. /**
  177. * @param string $expected
  178. * @param null|string $input
  179. *
  180. * @dataProvider provideFix70Cases
  181. * @requires PHP 7.0
  182. */
  183. public function test70($expected, $input = null)
  184. {
  185. $this->doTest($expected, $input);
  186. }
  187. public function provideFix70Cases()
  188. {
  189. return [
  190. [
  191. '<?php $a()(1);',
  192. '<?php $a () (1);',
  193. ],
  194. ];
  195. }
  196. }