* 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\ListNotation; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\Tests\Test\TestCaseUtils; /** * @internal * * @covers \PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer */ final class ListSyntaxFixerTest extends AbstractFixerTestCase { public function testFixWithDefaultConfiguration(): void { $this->fixer->configure([]); $this->doTest( 'fixer->configure(['syntax' => 'long']); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixToLongSyntaxCases(): iterable { // reverse testing $shortCases = self::provideFixToShortSyntaxCases(); foreach ($shortCases as $label => $shortCase) { if ('messy comments case' === $label) { continue; } yield $label => [$shortCase[1], $shortCase[0]]; } // the reverse of this is different because of all the comments and white space, // therefore we override with a similar case here yield 'comment case' => [ '{camel_case($attributes)}[$key] = $value; } }', ]; yield [' list($x, $y) = getList()];', ' [$x, $y] = getList()];', ]; } /** * @dataProvider provideFixToShortSyntaxCases */ public function testFixToShortSyntax(string $expected, ?string $input = null): void { $this->fixer->configure(['syntax' => 'short']); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixToShortSyntaxCases(): iterable { yield [ ' $a, "b" => $b, "c" => $c] = $array;', ' $a, "b" => $b, "c" => $c) = $array;', ]; yield [ '', '', ]; yield 'messy comments case' => [ 'fixer->configure(['syntax' => 'short']); $this->doTest($expected, $input); } /** * @dataProvider provideFixToLongSyntaxPhp72Cases */ public function testFixToLongSyntaxPhp72(string $expected, string $input): void { $this->fixer->configure(['syntax' => 'long']); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixToShortSyntaxPhp72Cases(): iterable { yield [ ' */ public static function provideFixToLongSyntaxPhp72Cases(): iterable { return TestCaseUtils::swapExpectedInputTestCases(self::provideFixToShortSyntaxPhp72Cases()); } /** * @dataProvider provideFixToShortSyntaxPhp73Cases */ public function testFixToShortSyntaxPhp73(string $expected, string $input): void { $this->fixer->configure(['syntax' => 'short']); $this->doTest($expected, $input); } /** * @dataProvider provideFixToLongSyntaxPhp73Cases */ public function testFixToLongSyntaxPhp73(string $expected, string $input): void { $this->fixer->configure(['syntax' => 'long']); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixToShortSyntaxPhp73Cases(): iterable { yield [ ' */ public static function provideFixToLongSyntaxPhp73Cases(): iterable { return TestCaseUtils::swapExpectedInputTestCases(self::provideFixToShortSyntaxPhp73Cases()); } /** * @dataProvider provideFix81Cases * * @requires PHP 8.1 */ public function testFix81(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield 'simple 8.1' => [ '