* 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 Kuba Werłos * * @covers \PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer * * @internal * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer */ final class OperatorLinebreakFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { foreach (self::pairs() as $key => $value) { yield \sprintf('%s when position is "beginning"', $key) => $value; yield \sprintf('%s when position is "end"', $key) => [ $value[1], $value[0], ['position' => 'end'], ]; } yield 'ignore add operator when only booleans enabled' => [ ' true], ]; yield 'handle operator when on separate line when position is "beginning"' => [ ' [ ' 'end'], ]; yield 'handle Elvis operator with space inside' => [ ' [ ' 'end'], ]; yield 'handle Elvis operator with comment inside' => [ ' [ ' 'end'], ]; yield 'assign by reference' => [ ' [ ' 'end'], ]; yield 'multiple switches' => [ ' [ ' [' [ ' 'beginning'], ]; yield 'nullable type when position is "end"' => [ ' 'end'], ]; } /** * @dataProvider provideFix80Cases * * @requires PHP 8.0 */ public function testFix80(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield 'handle ?-> operator' => [ ' $bar; ', ' $bar; ', ]; } /** * @return iterable}> */ private static function pairs(): iterable { yield 'handle equal sign' => [ ' [ ' false], ]; yield 'handle uppercase operator' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ '>', // Bitwise '&=', '|=', '^=', '<<=', '>>=', // Bitwise assignment '==', '===', '!=', '<>', '!==', '<', '>', '<=', '>=', // Comparison 'and', 'or', 'xor', '&&', '||', // Logical '.', '.=', // String '->', // Object '::', // Scope Resolution ]; $operators[] = '??'; $operators[] = '<=>'; foreach ($operators as $operator) { yield \sprintf('handle %s operator', $operator) => [ \sprintf(' operator' => [ ' $bar]; ', ' $bar]; ', ]; yield 'handle & operator with constant' => [ '