NoTrailingCommaInListCallFixerTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\ControlStructure;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer>
  22. */
  23. final class NoTrailingCommaInListCallFixerTest 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 [
  38. '<?php
  39. list($a, $b) = foo();
  40. list($a, , $c, $d) = foo();
  41. list($a, , $c) = foo();
  42. list($a) = foo();
  43. list($a , $b) = foo();
  44. list($a, /* $b */, $c) = foo();
  45. ',
  46. '<?php
  47. list($a, $b) = foo();
  48. list($a, , $c, $d, ) = foo();
  49. list($a, , $c, , ) = foo();
  50. list($a, , , , , ) = foo();
  51. list($a , $b , ) = foo();
  52. list($a, /* $b */, $c, ) = foo();
  53. ',
  54. ];
  55. yield [
  56. '<?php
  57. list(
  58. $a#
  59. ,#
  60. #
  61. ) = $a;',
  62. ];
  63. }
  64. }