* Dariusz RumiƄski * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Fixer\Basic; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer */ final class NoTrailingCommaInSinglelineFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield [ ' [ ' [ 'fixer->configure(['elements' => ['arguments']]); $this->doTest($expected, $input); } public static function provideFixNoTrailingCommaInSinglelineFunctionCallCases(): iterable { yield 'simple var' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'abc($a);', 'abc($a,);', ]; yield 'nested call' => [ 'abc($a,foo(1));', 'abc($a,foo(1,));', ]; yield 'wrapped' => [ 'getOutput(1);', 'getOutput(1,);', ]; yield 'dynamic function and method calls' => [ '$a(1); $c("");', '$a(1,); $c("",);', ]; yield 'static function call' => [ 'bar); $b = isset($foo->bar); ', 'bar,); $b = isset($foo->bar,); ', ]; yield 'unset' => [ ' [ ' [ ' static function(int $a): void{ echo $a;}, "d" => [ [2 => static function(int $a): void{ echo $a;}] ] ]; $a["e"](1); $a["d"][0][2](1); $z = new class { public static function b(int $a): void {echo $a; }}; $z::b(1); ${$e}(1); $$e(2); $f(0)(1); $g["e"](1); // foo', ' static function(int $a): void{ echo $a;}, "d" => [ [2 => static function(int $a): void{ echo $a;}] ] ]; $a["e"](1,); $a["d"][0][2](1,); $z = new class { public static function b(int $a): void {echo $a; }}; $z::b(1,); ${$e}(1,); $$e(2,); $f(0,)(1,); $g["e"](1,); // foo', ]; yield 'do not fix' => [ 'doTest($expected, $input); } public static function provideFix80NoTrailingCommaInSinglelineFunctionCallFixerCases(): iterable { yield [ 'doTest($expected, $input); } public static function provideFix81NoTrailingCommaInSinglelineFunctionCallFixerCases(): iterable { yield [ 'method(1); strlen(...);', 'method(1,); strlen(...);', ]; } /** * @dataProvider provideFixNoTrailingCommaInSinglelineArrayFixerCases */ public function testFixNoTrailingCommaInSinglelineArrayFixer(string $expected, ?string $input = null): void { $this->fixer->configure(['elements' => ['array']]); $this->doTest($expected, $input); } public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): iterable { yield ['fixer->configure(['elements' => ['array_destructuring']]); $this->doTest($expected, $input); } public static function provideFixNoTrailingCommaInListCallFixerCases(): iterable { yield [ '