* 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\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer> */ final class TernaryToElvisOperatorFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixCases(): iterable { $operators = ['+=', '-=', '*=', '**=', '/=', '.=', '%=', '&=', '|=', '^=', '<<=', '>>=']; foreach ($operators as $operator) { yield \sprintf('Test with operator "%s".', $operator) => [ \sprintf(' [ '$a ? : 1;', '$a ? $z->$a : 1;', ]; yield [ '$a;', '$a;', ]; yield [ ' [ ' [ ' [ ' [ ' [ ' [ '', '', ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre80Cases(): iterable { yield [ '{$b} ? $bar{0} : $foo;', ]; yield [ ' [ '$a[0] ? : 1;', '$a[0] ? __FILE__.$a.$b{2}.$c->$a[0] : 1;', ]; } /** * @dataProvider provideFix80Cases * * @requires PHP 8.0 */ public function testFix80(string $input): void { $this->doTest($input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield ['