MethodArgumentSpaceFixerTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
  14. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  15. use PhpCsFixer\WhitespacesFixerConfig;
  16. /**
  17. * @author Kuanhung Chen <ericj.tw@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer
  22. */
  23. final class MethodArgumentSpaceFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @var MethodArgumentSpaceFixer
  27. */
  28. protected $fixer;
  29. /**
  30. * @dataProvider provideFixCases
  31. */
  32. public function testFix(string $expected, ?string $input = null, array $configuration = []): void
  33. {
  34. $indent = ' ';
  35. $lineEnding = "\n";
  36. if (str_contains($expected, "\t")) {
  37. $indent = "\t";
  38. } elseif (preg_match('/\n \S/', $expected)) {
  39. $indent = ' ';
  40. }
  41. if (str_contains($expected, "\r")) {
  42. $lineEnding = "\r\n";
  43. }
  44. $this->fixer->configure($configuration);
  45. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig(
  46. $indent,
  47. $lineEnding
  48. ));
  49. $this->doTest($expected, $input);
  50. }
  51. /**
  52. * @dataProvider provideFixCases
  53. */
  54. public function testFixWithDifferentLineEndings(string $expected, ?string $input = null, array $configuration = []): void
  55. {
  56. if (null !== $input) {
  57. $input = str_replace("\n", "\r\n", $input);
  58. }
  59. $this->testFix(
  60. str_replace("\n", "\r\n", $expected),
  61. $input,
  62. $configuration
  63. );
  64. }
  65. public function provideFixCases(): array
  66. {
  67. return [
  68. [
  69. '<?php
  70. // space '.'
  71. $var1 = $a->some_method(
  72. $var2
  73. );
  74. // space '.'
  75. $var2 = some_function(
  76. $var2
  77. );
  78. // space '.'
  79. $var2a = $z[1](
  80. $var2a
  81. );
  82. '.'
  83. $var3 = function( $a, $b ) { };
  84. ',
  85. '<?php
  86. // space '.'
  87. $var1 = $a->some_method(
  88. $var2);
  89. // space '.'
  90. $var2 = some_function(
  91. $var2);
  92. // space '.'
  93. $var2a = $z[1](
  94. $var2a
  95. );
  96. '.'
  97. $var3 = function( $a , $b ) { };
  98. ',
  99. [
  100. 'on_multiline' => 'ensure_fully_multiline',
  101. ],
  102. ],
  103. 'default' => [
  104. '<?php xyz("", "", "", "");',
  105. '<?php xyz("","","","");',
  106. ],
  107. 'test method arguments' => [
  108. '<?php function xyz($a=10, $b=20, $c=30) {}',
  109. '<?php function xyz($a=10,$b=20,$c=30) {}',
  110. ],
  111. 'test method arguments with multiple spaces' => [
  112. '<?php function xyz($a=10, $b=20, $c=30) {}',
  113. '<?php function xyz($a=10, $b=20 , $c=30) {}',
  114. ],
  115. 'test method arguments with multiple spaces (kmsac)' => [
  116. '<?php function xyz($a=10, $b=20, $c=30) {}',
  117. '<?php function xyz($a=10, $b=20 , $c=30) {}',
  118. ['keep_multiple_spaces_after_comma' => true],
  119. ],
  120. 'test method call (I)' => [
  121. '<?php xyz($a=10, $b=20, $c=30);',
  122. '<?php xyz($a=10 ,$b=20,$c=30);',
  123. ],
  124. 'test method call (II)' => [
  125. '<?php xyz($a=10, $b=20, $this->foo(), $c=30);',
  126. '<?php xyz($a=10,$b=20 ,$this->foo() ,$c=30);',
  127. ],
  128. 'test method call with multiple spaces (I)' => [
  129. '<?php xyz($a=10, $b=20, $c=30);',
  130. '<?php xyz($a=10 , $b=20 , $c=30);',
  131. ],
  132. 'test method call with multiple spaces (I) (kmsac)' => [
  133. '<?php xyz($a=10, $b=20, $c=30);',
  134. '<?php xyz($a=10 , $b=20 , $c=30);',
  135. ['keep_multiple_spaces_after_comma' => true],
  136. ],
  137. 'test method call with tab' => [
  138. '<?php xyz($a=10, $b=20, $c=30);',
  139. "<?php xyz(\$a=10 , \$b=20 ,\t \$c=30);",
  140. ],
  141. 'test method call with tab (kmsac)' => [
  142. "<?php xyz(\$a=10, \$b=20,\t \$c=30);",
  143. "<?php xyz(\$a=10 , \$b=20 ,\t \$c=30);",
  144. ['keep_multiple_spaces_after_comma' => true],
  145. ],
  146. 'test method call with multiple spaces (II)' => [
  147. '<?php xyz($a=10, $b=20, $this->foo(), $c=30);',
  148. '<?php xyz($a=10,$b=20 , $this->foo() ,$c=30);',
  149. ],
  150. 'test method call with multiple spaces (II) (kmsac)' => [
  151. '<?php xyz($a=10, $b=20, $this->foo(), $c=30);',
  152. '<?php xyz($a=10,$b=20 , $this->foo() ,$c=30);',
  153. ['keep_multiple_spaces_after_comma' => true],
  154. ],
  155. 'test receiving data in list context with omitted values' => [
  156. '<?php list($a, $b, , , $c) = foo();',
  157. '<?php list($a, $b,, ,$c) = foo();',
  158. ],
  159. 'test receiving data in list context with omitted values and multiple spaces' => [
  160. '<?php list($a, $b, , , $c) = foo();',
  161. '<?php list($a, $b,, ,$c) = foo();',
  162. ],
  163. 'test receiving data in list context with omitted values and multiple spaces (kmsac)' => [
  164. '<?php list($a, $b, , , $c) = foo();',
  165. '<?php list($a, $b,, ,$c) = foo();',
  166. ['keep_multiple_spaces_after_comma' => true],
  167. ],
  168. 'skip array' => [
  169. '<?php array(10 , 20 ,30); $foo = [ 10,50 , 60 ] ?>',
  170. ],
  171. 'list call with trailing comma' => [
  172. '<?php list($path, $mode, ) = foo();',
  173. '<?php list($path, $mode,) = foo();',
  174. ],
  175. 'list call with trailing comma multi line' => [
  176. '<?php
  177. list(
  178. $a,
  179. $b,
  180. ) = foo();
  181. ',
  182. '<?php
  183. list(
  184. $a ,
  185. $b ,
  186. ) = foo();
  187. ',
  188. ],
  189. 'inline comments with spaces' => [
  190. '<?php xyz($a=10, /*comment1*/ $b=2000, /*comment2*/ $c=30);',
  191. '<?php xyz($a=10, /*comment1*/ $b=2000,/*comment2*/ $c=30);',
  192. ],
  193. 'inline comments with spaces (kmsac)' => [
  194. '<?php xyz($a=10, /*comment1*/ $b=2000, /*comment2*/ $c=30);',
  195. '<?php xyz($a=10, /*comment1*/ $b=2000,/*comment2*/ $c=30);',
  196. ['keep_multiple_spaces_after_comma' => true],
  197. ],
  198. 'multi line testing method call' => [
  199. '<?php if (1) {
  200. xyz(
  201. $a=10,
  202. $b=20,
  203. $c=30
  204. );
  205. }',
  206. '<?php if (1) {
  207. xyz(
  208. $a=10 ,
  209. $b=20,
  210. $c=30
  211. );
  212. }',
  213. ],
  214. 'skip arrays but replace arg methods' => [
  215. '<?php fnc(1, array(2, func2(6, 7) ,4), 5);',
  216. '<?php fnc(1,array(2, func2(6, 7) ,4), 5);',
  217. ],
  218. 'skip arrays but replace arg methods (kmsac)' => [
  219. '<?php fnc(1, array(2, func2(6, 7) ,4), 5);',
  220. '<?php fnc(1,array(2, func2(6, 7) ,4), 5);',
  221. ['keep_multiple_spaces_after_comma' => true],
  222. ],
  223. 'ignore commas inside call argument' => [
  224. '<?php fnc(1, array(2, 3 ,4), 5);',
  225. ],
  226. 'skip multi line array' => [
  227. '<?php
  228. array(
  229. 10 ,
  230. 20,
  231. 30
  232. );',
  233. ],
  234. 'skip short array' => [
  235. '<?php
  236. $foo = ["a"=>"apple", "b"=>"bed" ,"c"=>"car"];
  237. $bar = ["a" ,"b" ,"c"];
  238. ',
  239. ],
  240. 'don\'t change HEREDOC and NOWDOC' => [
  241. "<?php if (1) {
  242. \$this->foo(
  243. <<<EOTXTa
  244. heredoc
  245. EOTXTa
  246. ,
  247. <<<'EOTXTb'
  248. nowdoc
  249. EOTXTb
  250. ,
  251. 'foo'
  252. );
  253. }",
  254. ],
  255. 'with_random_comments on_multiline:ignore' => [
  256. '<?php xyz#
  257. (#
  258. ""#
  259. ,#
  260. $a#
  261. );',
  262. null,
  263. ['on_multiline' => 'ignore'],
  264. ],
  265. 'with_random_comments on_multiline:ensure_single_line' => [
  266. '<?php xyz#
  267. (#
  268. ""#
  269. ,#
  270. $a#
  271. );',
  272. null,
  273. ['on_multiline' => 'ensure_single_line'],
  274. ],
  275. 'with_random_comments on_multiline:ensure_fully_multiline' => [
  276. '<?php xyz#
  277. (#
  278. ""#
  279. ,#
  280. $a#
  281. );',
  282. '<?php xyz#
  283. (#
  284. ""#
  285. ,#
  286. $a#
  287. );',
  288. ['on_multiline' => 'ensure_fully_multiline'],
  289. ],
  290. 'test half-multiline function becomes fully-multiline' => [
  291. <<<'EXPECTED'
  292. <?php
  293. functionCall(
  294. 'a',
  295. 'b',
  296. 'c'
  297. );
  298. EXPECTED
  299. ,
  300. <<<'INPUT'
  301. <?php
  302. functionCall(
  303. 'a', 'b',
  304. 'c'
  305. );
  306. INPUT
  307. ,
  308. ],
  309. 'test wrongly formatted half-multiline function becomes fully-multiline' => [
  310. '<?php
  311. f(
  312. 1,
  313. 2,
  314. 3
  315. );',
  316. '<?php
  317. f(1,2,
  318. 3);',
  319. ],
  320. 'function calls with here doc cannot be anything but multiline' => [
  321. <<<'EXPECTED'
  322. <?php
  323. str_replace(
  324. "\n",
  325. PHP_EOL,
  326. <<<'TEXT'
  327. 1) someFile.php
  328. TEXT
  329. );
  330. EXPECTED
  331. ,
  332. <<<'INPUT'
  333. <?php
  334. str_replace("\n", PHP_EOL, <<<'TEXT'
  335. 1) someFile.php
  336. TEXT
  337. );
  338. INPUT
  339. ,
  340. ],
  341. 'test barely multiline function with blank lines becomes fully-multiline' => [
  342. <<<'EXPECTED'
  343. <?php
  344. functionCall(
  345. 'a',
  346. 'b',
  347. 'c'
  348. );
  349. EXPECTED
  350. ,
  351. <<<'INPUT'
  352. <?php
  353. functionCall('a', 'b',
  354. 'c');
  355. INPUT
  356. ,
  357. ],
  358. 'test indentation is preserved' => [
  359. <<<'EXPECTED'
  360. <?php
  361. if (true) {
  362. functionCall(
  363. 'a',
  364. 'b',
  365. 'c'
  366. );
  367. }
  368. EXPECTED
  369. ,
  370. <<<'INPUT'
  371. <?php
  372. if (true) {
  373. functionCall(
  374. 'a', 'b',
  375. 'c'
  376. );
  377. }
  378. INPUT
  379. ,
  380. ],
  381. 'test multiline array arguments do not trigger multiline' => [
  382. <<<'EXPECTED'
  383. <?php
  384. defraculate(1, array(
  385. 'a',
  386. 'b',
  387. 'c',
  388. ), 42);
  389. EXPECTED
  390. ,
  391. ],
  392. 'test multiline function arguments do not trigger multiline' => [
  393. <<<'EXPECTED'
  394. <?php
  395. defraculate(1, function () {
  396. $a = 42;
  397. }, 42);
  398. EXPECTED
  399. ,
  400. ],
  401. 'test violation after opening parenthesis' => [
  402. <<<'EXPECTED'
  403. <?php
  404. defraculate(
  405. 1,
  406. 2,
  407. 3
  408. );
  409. EXPECTED
  410. ,
  411. <<<'INPUT'
  412. <?php
  413. defraculate(
  414. 1, 2, 3);
  415. INPUT
  416. ,
  417. ],
  418. 'test violation after opening parenthesis, indented with two spaces' => [
  419. <<<'EXPECTED'
  420. <?php
  421. defraculate(
  422. 1,
  423. 2,
  424. 3
  425. );
  426. EXPECTED
  427. ,
  428. <<<'INPUT'
  429. <?php
  430. defraculate(
  431. 1, 2, 3);
  432. INPUT
  433. ,
  434. ],
  435. 'test violation after opening parenthesis, indented with tabs' => [
  436. <<<'EXPECTED'
  437. <?php
  438. defraculate(
  439. 1,
  440. 2,
  441. 3
  442. );
  443. EXPECTED
  444. ,
  445. <<<'INPUT'
  446. <?php
  447. defraculate(
  448. 1, 2, 3);
  449. INPUT
  450. ,
  451. ],
  452. 'test violation before closing parenthesis' => [
  453. <<<'EXPECTED'
  454. <?php
  455. defraculate(
  456. 1,
  457. 2,
  458. 3
  459. );
  460. EXPECTED
  461. ,
  462. <<<'INPUT'
  463. <?php
  464. defraculate(1, 2, 3
  465. );
  466. INPUT
  467. ,
  468. ],
  469. 'test violation before closing parenthesis in nested call' => [
  470. <<<'EXPECTED'
  471. <?php
  472. getSchwifty('rick', defraculate(
  473. 1,
  474. 2,
  475. 3
  476. ), 'morty');
  477. EXPECTED
  478. ,
  479. <<<'INPUT'
  480. <?php
  481. getSchwifty('rick', defraculate(1, 2, 3
  482. ), 'morty');
  483. INPUT
  484. ,
  485. ],
  486. 'test with comment between arguments' => [
  487. <<<'EXPECTED'
  488. <?php
  489. functionCall(
  490. 'a', /* comment */
  491. 'b',
  492. 'c'
  493. );
  494. EXPECTED
  495. ,
  496. <<<'INPUT'
  497. <?php
  498. functionCall(
  499. 'a',/* comment */'b',
  500. 'c'
  501. );
  502. INPUT
  503. ,
  504. ],
  505. 'test with deeply nested arguments' => [
  506. <<<'EXPECTED'
  507. <?php
  508. foo(
  509. 'a',
  510. 'b',
  511. [
  512. 'c',
  513. 'd', bar('e', 'f'),
  514. baz(
  515. 'g',
  516. ['h',
  517. 'i',
  518. ]
  519. ),
  520. ]
  521. );
  522. EXPECTED
  523. ,
  524. <<<'INPUT'
  525. <?php
  526. foo('a',
  527. 'b',
  528. [
  529. 'c',
  530. 'd', bar('e', 'f'),
  531. baz('g',
  532. ['h',
  533. 'i',
  534. ]),
  535. ]);
  536. INPUT
  537. ,
  538. ],
  539. 'multiline string argument' => [
  540. <<<'UNAFFECTED'
  541. <?php
  542. $this->with('<?php
  543. %s
  544. class FooClass
  545. {
  546. }', $comment, false);
  547. UNAFFECTED
  548. ,
  549. ],
  550. 'arrays with whitespace inside' => [
  551. <<<'UNAFFECTED'
  552. <?php
  553. $a = array/**/( 1);
  554. $a = array/**/( 12,
  555. 7);
  556. $a = array/***/(123, 7);
  557. $a = array ( 1,
  558. 2);
  559. UNAFFECTED
  560. ,
  561. ],
  562. 'test code that should not be affected (because not a function nor a method)' => [
  563. <<<'UNAFFECTED'
  564. <?php
  565. if (true &&
  566. true
  567. ) {
  568. // do whatever
  569. }
  570. UNAFFECTED
  571. ,
  572. ],
  573. 'test ungodly code' => [
  574. <<<'EXPECTED'
  575. <?php
  576. $a = function#
  577. (#
  578. #
  579. $a#
  580. #
  581. ,#
  582. #
  583. $b,
  584. $c#
  585. #
  586. )#
  587. use (
  588. $b1,
  589. $c1,
  590. $d1
  591. ) {
  592. };
  593. EXPECTED
  594. ,
  595. <<<'INPUT'
  596. <?php
  597. $a = function#
  598. (#
  599. #
  600. $a#
  601. #
  602. ,#
  603. #
  604. $b,$c#
  605. #
  606. )#
  607. use ($b1,
  608. $c1,$d1) {
  609. };
  610. INPUT
  611. ,
  612. ],
  613. 'test list' => [
  614. <<<'UNAFFECTED'
  615. <?php
  616. // no fix
  617. list($a,
  618. $b, $c) = $a;
  619. isset($a,
  620. $b, $c);
  621. unset($a,
  622. $b, $c);
  623. array(1,
  624. 2,3
  625. );
  626. UNAFFECTED
  627. ,
  628. ],
  629. 'test function argument with multiline echo in it' => [
  630. <<<'UNAFFECTED'
  631. <?php
  632. call_user_func(function ($arguments) {
  633. echo 'a',
  634. 'b';
  635. }, $argv);
  636. UNAFFECTED
  637. ,
  638. ],
  639. 'test function argument with oneline echo in it' => [
  640. <<<'EXPECTED'
  641. <?php
  642. call_user_func(
  643. function ($arguments) {
  644. echo 'a', 'b';
  645. },
  646. $argv
  647. );
  648. EXPECTED
  649. ,
  650. <<<'INPUT'
  651. <?php
  652. call_user_func(function ($arguments) {
  653. echo 'a', 'b';
  654. },
  655. $argv);
  656. INPUT
  657. ,
  658. ],
  659. 'ensure_single_line' => [
  660. <<<'EXPECTED'
  661. <?php
  662. function foo($a, $b) {
  663. // foo
  664. }
  665. foo($a, $b);
  666. EXPECTED
  667. ,
  668. <<<'INPUT'
  669. <?php
  670. function foo(
  671. $a,
  672. $b
  673. ) {
  674. // foo
  675. }
  676. foo(
  677. $a,
  678. $b
  679. );
  680. INPUT
  681. ,
  682. ['on_multiline' => 'ensure_single_line'],
  683. ],
  684. 'ensure_single_line_with_random_comments' => [
  685. <<<'EXPECTED'
  686. <?php
  687. function foo(/* foo */// bar
  688. $a, /* foo */// bar
  689. $b#foo
  690. ) {
  691. // foo
  692. }
  693. foo(/* foo */// bar
  694. $a, /* foo */// bar
  695. $b#foo
  696. );
  697. EXPECTED
  698. ,
  699. null,
  700. ['on_multiline' => 'ensure_single_line'],
  701. ],
  702. 'ensure_single_line_with_consecutive_newlines' => [
  703. <<<'EXPECTED'
  704. <?php
  705. function foo($a, $b) {
  706. // foo
  707. }
  708. foo($a, $b);
  709. EXPECTED
  710. ,
  711. <<<'INPUT'
  712. <?php
  713. function foo(
  714. $a,
  715. $b
  716. ) {
  717. // foo
  718. }
  719. foo(
  720. $a,
  721. $b
  722. );
  723. INPUT
  724. ,
  725. ['on_multiline' => 'ensure_single_line'],
  726. ],
  727. 'ensure_single_line_methods' => [
  728. <<<'EXPECTED'
  729. <?php
  730. class Foo {
  731. public static function foo1($a, $b, $c) {}
  732. private function foo2($a, $b, $c) {}
  733. }
  734. EXPECTED
  735. ,
  736. <<<'INPUT'
  737. <?php
  738. class Foo {
  739. public static function foo1(
  740. $a,
  741. $b,
  742. $c
  743. ) {}
  744. private function foo2(
  745. $a,
  746. $b,
  747. $c
  748. ) {}
  749. }
  750. INPUT
  751. ,
  752. ['on_multiline' => 'ensure_single_line'],
  753. ],
  754. 'ensure_single_line_keep_spaces_after_comma' => [
  755. <<<'EXPECTED'
  756. <?php
  757. function foo($a, $b) {
  758. // foo
  759. }
  760. foo($a, $b);
  761. EXPECTED
  762. ,
  763. <<<'INPUT'
  764. <?php
  765. function foo(
  766. $a,
  767. $b
  768. ) {
  769. // foo
  770. }
  771. foo(
  772. $a,
  773. $b
  774. );
  775. INPUT
  776. ,
  777. [
  778. 'on_multiline' => 'ensure_single_line',
  779. 'keep_multiple_spaces_after_comma' => true,
  780. ],
  781. ],
  782. 'fix closing parenthesis (without trailing comma)' => [
  783. '<?php
  784. if (true) {
  785. execute(
  786. $foo,
  787. $bar
  788. );
  789. }',
  790. '<?php
  791. if (true) {
  792. execute(
  793. $foo,
  794. $bar
  795. );
  796. }',
  797. [
  798. 'on_multiline' => 'ensure_fully_multiline',
  799. ],
  800. ],
  801. 'test anonymous functions' => [
  802. '<?php
  803. $example = function () use ($message1, $message2) {
  804. };',
  805. '<?php
  806. $example = function () use ($message1,$message2) {
  807. };',
  808. ],
  809. ];
  810. }
  811. /**
  812. * @dataProvider provideFix56Cases
  813. */
  814. public function testFix56(string $expected, string $input): void
  815. {
  816. $this->doTest($expected, $input);
  817. }
  818. public function provideFix56Cases(): array
  819. {
  820. return [
  821. [
  822. '<?php function A($c, ...$a){}',
  823. '<?php function A($c ,...$a){}',
  824. ],
  825. ];
  826. }
  827. /**
  828. * @dataProvider provideFix73Cases
  829. * @requires PHP 7.3
  830. */
  831. public function testFix73(string $expected, ?string $input = null, array $config = []): void
  832. {
  833. $this->fixer->configure($config);
  834. $this->doTest($expected, $input);
  835. }
  836. public function provideFix73Cases(): array
  837. {
  838. return [
  839. [
  840. <<<'EXPECTED'
  841. <?php
  842. foo(
  843. <<<'EOD'
  844. bar
  845. EOD,
  846. 'baz'
  847. );
  848. EXPECTED
  849. ,
  850. <<<'INPUT'
  851. <?php
  852. foo(
  853. <<<'EOD'
  854. bar
  855. EOD
  856. ,
  857. 'baz'
  858. );
  859. INPUT
  860. ,
  861. ['after_heredoc' => true],
  862. ],
  863. [
  864. <<<'EXPECTED'
  865. <?php
  866. foo(
  867. $bar,
  868. $baz,
  869. );
  870. EXPECTED
  871. ,
  872. null,
  873. ['on_multiline' => 'ensure_fully_multiline'],
  874. ],
  875. [
  876. '<?php
  877. functionCall(
  878. 1,
  879. 2,
  880. 3,
  881. );',
  882. '<?php
  883. functionCall(
  884. 1, 2,
  885. 3,
  886. );',
  887. [
  888. 'on_multiline' => 'ensure_fully_multiline',
  889. ],
  890. ],
  891. [
  892. '<?php foo(1, 2, 3, );',
  893. '<?php foo(1,2,3,);',
  894. ],
  895. ];
  896. }
  897. /**
  898. * @dataProvider provideFix74Cases
  899. * @requires PHP 7.4
  900. */
  901. public function testFix74(string $expected, ?string $input = null, array $config = []): void
  902. {
  903. $this->fixer->configure($config);
  904. $this->doTest($expected, $input);
  905. }
  906. public function provideFix74Cases(): array
  907. {
  908. return [
  909. [
  910. '<?php
  911. $fn = fn(
  912. $test1,
  913. $test2
  914. ) => null;',
  915. '<?php
  916. $fn = fn(
  917. $test1, $test2
  918. ) => null;',
  919. [
  920. 'on_multiline' => 'ensure_fully_multiline',
  921. ],
  922. ],
  923. ];
  924. }
  925. /**
  926. * @dataProvider provideFix81Cases
  927. * @requires PHP 8.1
  928. */
  929. public function testFix81(string $expected, ?string $input = null): void
  930. {
  931. $this->doTest($expected, $input);
  932. }
  933. public function provideFix81Cases(): \Generator
  934. {
  935. yield [
  936. '<?php
  937. [Foo::class, \'method\'](
  938. ...
  939. ) ?>',
  940. '<?php
  941. [Foo::class, \'method\']( ...
  942. ) ?>',
  943. ];
  944. }
  945. }