* 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\Operator; use PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\AbstractShortOperatorFixer * @covers \PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer> */ final class LongToShorthandOperatorFixerTest 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 'simple I' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' $constant) { yield 'c #'.$i => [ \sprintf(' [ \sprintf(' [ \sprintf(' '*=', '|' => '|=', '&' => '&=', '^' => '^='] as $operator => $shortHand) { yield \sprintf('commutative operator "%s".', $operator) => [ \sprintf(' [ ' [ ' [ ' [ 'getStaticProperties()['operators']; foreach ($operators as $operator => $info) { $shortHand = $info[1]; yield \sprintf('Simple test with operator "%s" var/var.', $operator) => [ \sprintf(' [ \sprintf('', '', ]; yield [ ' [ ' [ ' [ ' [ ' [ '', '', ]; yield [ ' ['= $b; $a[1] = $a[1] instanceof \Foo & $b; ']; yield ['']; yield ['']; // do not fix; not assignment yield [' [ '', '', ]; yield 'simple V, comments, reverse' => [ ' [ ' [ ' [ ' [ ' [ ' [ 'test += $i; } }', 'test = $this->test + $i; } }', ]; } /** * @requires PHP <8.0 * * @dataProvider provideFixPre80Cases */ public function testFixPre80(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre80Cases(): iterable { yield [ ' [ ' [ ' [ ' [ '', '', ]; } }