* 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 */ final class StatementIndentationFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } 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 'if with only a comment and followed by else' => [ ' [ ' [ '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' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t")); $this->doTest($expected, $input); } public static function provideFixWithTabsCases(): iterable { yield 'simple' => [ "doTest($expected, $input); } public static function provideFixPhp80Cases(): iterable { yield 'match expression' => [ ' false, 1 => true, default => throw new Exception(), };', ' false, 1 => true, default => throw new Exception(), };', ]; yield 'attribute' => [ 'doTest($expected, $input); } public static function provideFixPhp81Cases(): iterable { yield 'simple enum' => [ ' [ ' [ '