* 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\Whitespace; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; /** * @internal * * @covers \PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer */ final class StatementIndentationFixerTest 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); } /** * @return iterable}> */ public static function provideFixCases(): iterable { yield 'no brace block' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'bar() ->baz() ; }', 'bar() ->baz() ; }', ]; yield 'nested arrays (long syntax)' => [ 'bar() , array($baz) ) ; }', 'bar() , array($baz) ) ; }', ]; yield 'nested arrays (short syntax)' => [ 'bar() , [$baz] ] ; }', 'bar() , [$baz] ] ; }', ]; yield 'array (long syntax) with function call' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'bar( $baz );', 'bar( $baz );', ]; yield 'argument separator on its own line' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' null;', ' null;', ]; yield 'multiline list in foreach' => [ ' $foo, "bar" => $bar, ]) { }', ]; yield 'switch case with control structure' => [ ' [ 'baz() /* ->baz() */ ;', ]; yield 'multiple anonymous functions as function arguments' => [ ' [ 'bar(function ($a) { echo $a; }, function ($b) { echo $b; }) ;', ]; yield 'semicolon on a newline inside a switch case without break statement' => [ 'baz() ; }', ]; yield 'alternative syntax' => [ '
', ]; yield 'trait import with conflict resolution' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' false], ]; yield 'comment before else blocks WITH stick_comment_to_next_continuous_control_statement' => [ ' true], ]; yield 'multiline comment in block - describing next block' => [ ' true], ]; yield 'multiline comment in block - the only content in block' => [ ' [ ' true], ]; yield 'comments at the end of if/elseif/else blocks' => [ ' true], ]; yield 'if-elseif-else without braces' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' 1, \'b\' => 2, ]; }', ]; yield 'array with static method call' => [ ' [ <<<'PHP' fixer->configure($configuration); $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t")); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixWithTabsCases(): iterable { yield 'simple' => [ "fixer->configure($configuration); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixPhp80Cases(): iterable { yield 'match expression' => [ ' false, 1 => true, default => throw new Exception(), };', ' false, 1 => true, default => throw new Exception(), };', ]; yield 'attribute' => [ 'fixer->configure($configuration); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixPhp81Cases(): iterable { yield 'simple enum' => [ ' [ ' [ ' [ '