* 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 * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer */ final class NoTrailingCommaInSinglelineFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); $this->doTest($expected, $input); } /** * @return iterable}}> */ public static function provideFixCases(): iterable { yield [ ' [ ' [ ' [ ' ['arguments']], ]; yield '&' => [ ' ['arguments']], ]; yield 'open' => [ ' ['arguments']], ]; yield '=' => [ ' ['arguments']], ]; yield '.' => [ ' ['arguments']], ]; yield '(' => [ ' ['arguments']], ]; yield '\\' => [ ' ['arguments']], ]; yield 'A\\' => [ ' ['arguments']], ]; yield '\A\\' => [ ' ['arguments']], ]; yield ';' => [ ' ['arguments']], ]; yield '}' => [ ' ['arguments']], ]; yield 'test method call' => [ 'abc($a);', 'abc($a,);', ['elements' => ['arguments']], ]; yield 'nested call' => [ 'abc($a,foo(1));', 'abc($a,foo(1,));', ['elements' => ['arguments']], ]; yield 'wrapped' => [ 'getOutput(1);', 'getOutput(1,);', ['elements' => ['arguments']], ]; yield 'dynamic function and method calls' => [ '$a(1); $c("");', '$a(1,); $c("",);', ['elements' => ['arguments']], ]; yield 'static function call' => [ 'bar); $b = isset($foo->bar); ', 'bar,); $b = isset($foo->bar,); ', ['elements' => ['arguments']], ]; yield 'unset' => [ ' ['arguments']], ]; yield 'anonymous_class construction' => [ ' ['arguments']], ]; yield 'array/property access call' => [ ' 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', ['elements' => ['arguments']], ]; yield 'do not fix' => [ ' ['arguments']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ " ['array']], ]; yield [ " ['array']], ]; yield [ " ['array']], ]; yield [ " ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; // Short syntax yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ " ['array']], ]; yield [ " ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array_destructuring']], ]; yield [ ' ['array_destructuring']], ]; yield [ ' ['array_destructuring']], ]; } /** * @dataProvider provideFix80Cases * * @requires PHP 8.0 */ public function testFix80(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield [ 'method(1); strlen(...);', 'method(1,); strlen(...);', ]; } }