* 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 Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Fixer\Operator\NewWithBracesFixer */ final class NewWithBracesFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @dataProvider provideFix70Cases * @requires PHP 7.0 */ public function testFix70(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } public function provideFixCases() { $tests = [ [ 'bar(); $bar2 = new $foo[0][1]->bar(); ', ], [ 'foo;', 'foo;', ], [ 'bar))->foo;', 'bar))->foo;', ], [ ' new DateTime(), );', ' new DateTime, );', ], [ ' new DateTime() );', ' new DateTime );', ], [ ' ', '', ], [ '> 1; ', '> 1; ', ], [ ' $this->startDate) {} if (new DateTime() >= $this->startDate) {} if (new DateTime() < $this->startDate) {} if (new DateTime() <= $this->startDate) {} if (new DateTime() == $this->startDate) {} if (new DateTime() != $this->startDate) {} if (new DateTime() <> $this->startDate) {} if (new DateTime() === $this->startDate) {} if (new DateTime() !== $this->startDate) {} ', ' $this->startDate) {} if (new DateTime >= $this->startDate) {} if (new DateTime < $this->startDate) {} if (new DateTime <= $this->startDate) {} if (new DateTime == $this->startDate) {} if (new DateTime != $this->startDate) {} if (new DateTime <> $this->startDate) {} if (new DateTime === $this->startDate) {} if (new DateTime !== $this->startDate) {} ', ], [ ' 1];', ' 1];', ], [ ' new DateTime(), ];', ' new DateTime, ];', ], [ ' new DateTime() ];', ' new DateTime ];', ], [ ' $test) { yield $index => $test; } if (\PHP_VERSION_ID < 80000) { yield [ '', '', ]; yield [ ' 1; ', ' 1; ', ], [ ' ', ' ', ], [ 'doTest($expected, $input); } public function provideFix80Cases() { yield [ 'bar(); $bar2 = new $foo[0][1]?->bar(); ', ]; } }