* 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\Alias; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\Alias\ArrayPushFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Alias\ArrayPushFixer> */ final class ArrayPushFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixCases(): iterable { yield 'minimal' => [ ' [ ' [ ' [ ' [ ' [ '', '', ]; yield ') before' => [ ' 0) $a[] = $c; ', ' 0) array_push($a, $c); ', ]; yield '} before' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'bar[] = 1;', 'bar, 1);', ]; yield [ '$c[] = $b;', '$c, $b);', ]; yield [ '$c[1]->$d[$a--]->$a[7][] = $b;', '$c[1]->$d[$a--]->$a[7], $b);', ]; yield 'push multiple' => [ ' [ '$a(1,2), $c);', ]; yield 'push multiple short' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'array_push($a, $b19); ', ]; yield 'open echo' => [ ' ', ]; yield 'ellipsis' => [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre80Cases(): iterable { yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'c[2], $b19);', ]; } /** * @dataProvider provideFix81Cases * * @requires PHP 8.1 */ public function testFix81(string $expected, string $input): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield 'simple 8.1' => [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre84Cases(): iterable { yield [ '$c[1]->$d{$a--}->$a[7][] = $b;', '$c[1]->$d{$a--}->$a[7], $b);', ]; } }