* 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; /** * @author Filippo Tessarotto * * @internal * * @covers \PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer> */ final class TernaryToNullCoalescingFixerTest 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 // Do not fix cases. [' [ ' [ ' [ '', '', ]; yield [ 'a ?? null;', 'a) ? $obj->a : null;', ]; yield [ 'a->b ?? null;', 'a->b) ? $obj->a->b : null;', ]; yield [ '$a ?? null;', '$a) ? $obj->$a : null;', ]; yield [ 'a->$b ?? null;', 'a->$b) ? $obj->a->$b : null;', ]; yield [ 'a[3] ?? null;', 'a[3]) ? $obj->a[3] : null;', ]; yield [ 'a[\'foo\'] ?? null;', 'a[\'foo\']) ? $obj->a[\'foo\'] : null;', ]; yield [ 'a[$b] ?? null;', 'a[$b]) ? $obj->a[$b] : null;', ]; yield [ 'a[$b][\'foo\'] ?? null;', 'a[$b][\'foo\']) ? $obj->a[$b][\'foo\'] : null;', ]; yield [ 'a[$b[\'foo\']] ?? null;', 'a[$b[\'foo\']]) ? $obj->a[$b[\'foo\']] : null;', ]; yield [ 'b] ?? null;', 'b]) ? $a[$obj->b] : null;', ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre80Cases(): iterable { yield ['