* 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\NewWithParenthesesFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer */ final class NewWithParenthesesFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixNamedWithDefaultConfigurationCases */ public function testFixNamedWithDefaultConfiguration(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixNamedWithDefaultConfigurationCases(): iterable { yield ['bar(); $bar2 = new $foo[0][1]->bar(); ', ]; yield [ 'foo;', 'foo;', ]; yield [ 'bar))->foo;', 'bar))->foo;', ]; yield [ ' new DateTime(), );', ' new DateTime, );', ]; yield [ ' new DateTime() );', ' new DateTime );', ]; yield [ ' ', '', ]; yield [ '> 1; ', '> 1; ', ]; yield [ ' $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) {} ', ]; yield [ ' 1];', ' 1];', ]; yield [ ' new DateTime(), ];', ' new DateTime, ];', ]; yield [ ' new DateTime() ];', ' new DateTime ];', ]; yield [ ' 1; ', ' 1; ', ]; yield [ "fixer->configure(['named_class' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixNamedWithoutParenthesesCases(): iterable { yield ['bar["baz"];', 'bar["baz"]();', ]; yield [ 'foo;', 'foo;', ]; yield [ 'bar))->foo;', 'bar))->foo;', ]; yield [ ' new DateTime, );', ' new DateTime(), );', ]; yield [ ' new DateTime );', ' new DateTime() );', ]; yield [ ' ', '', ]; yield [ '> 1; ', '> 1; ', ]; yield [ ' $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) {} ', ]; yield [ ' 1];', ' 1];', ]; yield [ ' new DateTime, ];', ' new DateTime(), ];', ]; yield [ ' new DateTime ];', ' new DateTime() ];', ]; yield [ ' 1; ', ' 1; ', ]; yield [ "doTest($expected, $input); } /** * @return iterable */ public static function provideFixAnonymousWithDefaultConfigurationCases(): iterable { yield ['f ) extends Bar2 implements Foo{};']; yield ['']; yield [ ' 1; ', ' 1; ', ]; yield [ ' ', ' ', ]; yield [ 'fixer->configure(['anonymous_class' => false]); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixAnonymousWithoutParenthesesCases(): iterable { yield ['f ) extends Bar2 implements Foo{};']; yield ['']; yield [ ' ', ' ', ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre80Cases(): iterable { yield [ '', '', ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'bar(); $bar2 = new $foo[0][1]?->bar(); ', ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield [ '