* 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\LanguageConstruct; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Andreas Möller * * @internal * * @covers \PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAfterConstructFixer */ final class SingleSpaceAfterConstructFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideInvalidConstructCases * * @param mixed $construct */ public function testConfigureRejectsInvalidControlStatement($construct): void { $this->expectException(InvalidFixerConfigurationException::class); $this->fixer->configure([ 'constructs' => [ $construct, ], ]); } public function provideInvalidConstructCases(): array { return [ 'null' => [null], 'false' => [false], 'true' => [true], 'int' => [0], 'float' => [3.14], 'array' => [[]], 'object' => [new \stdClass()], 'unknown' => ['foo'], ]; } /** * @dataProvider provideFixWithAbstractCases */ public function testFixWithAbstract(string $expected, ?string $input = null): void { $this->fixer->configure([ 'constructs' => [ 'abstract', ], ]); $this->doTest($expected, $input); } public function provideFixWithAbstractCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'break', ], ]); $this->doTest($expected, $input); } public function provideFixWithBreakCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'as', ], ]); $this->doTest($expected, $input); } public function provideFixWithAsCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'case', ], ]); $this->doTest($expected, $input); } public function provideFixWithCaseCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'catch', ], ]); $this->doTest($expected, $input); } public function provideFixWithCatchCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'class', ], ]); $this->doTest($expected, $input); } public function provideFixWithClassCases(): array { return [ [ ' ['class']], ], [ ' ['class']], ], [ ' ['class']], ], [ ' ['class']], ], [ ' ['class']], ], [ ' ['return']], ], ]; } /** * @dataProvider provideFixWithContinueCases */ public function testFixWithContinue(string $expected, ?string $input = null): void { $this->fixer->configure([ 'constructs' => [ 'continue', ], ]); $this->doTest($expected, $input); } public function provideFixWithContinueCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'const', ], ]); $this->doTest($expected, $input); } public function provideFixWithConstCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'const_import', ], ]); $this->doTest($expected, $input); } public function provideFixWithConstImportCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'clone', ], ]); $this->doTest($expected, $input); } public function provideFixWithCloneCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'do', ], ]); $this->doTest($expected, $input); } public function provideFixWithDoCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'echo', ], ]); $this->doTest($expected, $input); } public function provideFixWithEchoCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'else', ], ]); $this->doTest($expected, $input); } public function provideFixWithElseCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'elseif', ], ]); $this->doTest($expected, $input); } public function provideFixWithElseIfCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'extends', ], ]); $this->doTest($expected, $input); } public function provideFixWithExtendsCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'final', ], ]); $this->doTest($expected, $input); } public function provideFixWithFinalCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'finally', ], ]); $this->doTest($expected, $input); } public function provideFixWithFinallyCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'for', ], ]); $this->doTest($expected, $input); } public function provideFixWithForCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'foreach', ], ]); $this->doTest($expected, $input); } public function provideFixWithForeachCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'function', ], ]); $this->doTest($expected, $input); } public function provideFixWithFunctionCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'function_import', ], ]); $this->doTest($expected, $input); } public function provideFixWithFunctionImportCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'global', ], ]); $this->doTest($expected, $input); } public function provideFixWithGlobalCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'goto', ], ]); $this->doTest($expected, $input); } public function provideFixWithGotoCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'if', ], ]); $this->doTest($expected, $input); } public function provideFixWithIfCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'implements', ], ]); $this->doTest($expected, $input); } public function provideFixWithImplementsCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'include', ], ]); $this->doTest($expected, $input); } public function provideFixWithIncludeCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'include_once', ], ]); $this->doTest($expected, $input); } public function provideFixWithIncludeOnceCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'instanceof', ], ]); $this->doTest($expected, $input); } public function provideFixWithInstanceofCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'insteadof', ], ]); $this->doTest($expected, $input); } public function provideFixWithInsteadofCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'interface', ], ]); $this->doTest($expected, $input); } public function provideFixWithInterfaceCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'new', ], ]); $this->doTest($expected, $input); } public function provideFixWithNewCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'open_tag_with_echo', ], ]); $this->doTest($expected, $input); } public function provideFixWithOpenTagWithEchoCases(): array { return [ [ '', '', ], [ '', '', ], [ '', '', ], [ '', '', ], [ '', '', ], ]; } /** * @dataProvider provideFixWithPrintCases */ public function testFixWithPrint(string $expected, ?string $input = null): void { $this->fixer->configure([ 'constructs' => [ 'print', ], ]); $this->doTest($expected, $input); } public function provideFixWithPrintCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'private', ], ]); $this->doTest($expected, $input); } public function provideFixWithPrivateCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'private', ], ]); $this->doTest($expected, $input); } public function provideFixWithPrivatePhp71Cases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'protected', ], ]); $this->doTest($expected, $input); } public function provideFixWithProtectedCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'protected', ], ]); $this->doTest($expected, $input); } public function provideFixWithProtectedPhp71Cases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'public', ], ]); $this->doTest($expected, $input); } public function provideFixWithPublicCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'public', ], ]); $this->doTest($expected, $input); } public function provideFixWithPublicPhp71Cases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'require', ], ]); $this->doTest($expected, $input); } public function provideFixWithRequireCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'require_once', ], ]); $this->doTest($expected, $input); } public function provideFixWithRequireOnceCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'return', ], ]); $this->doTest($expected, $input); } public function provideFixWithReturnCases(): array { return [ [ '', '', ], [ '', ], ]; } /** * @dataProvider provideFixWithStaticCases */ public function testFixWithStatic(string $expected, ?string $input = null): void { $this->fixer->configure([ 'constructs' => [ 'static', ], ]); $this->doTest($expected, $input); } public function provideFixWithStaticCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'throw', ], ]); $this->doTest($expected, $input); } public function provideFixWithThrowCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'trait', ], ]); $this->doTest($expected, $input); } public function provideFixWithTraitCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'try', ], ]); $this->doTest($expected, $input); } public function provideFixWithTryCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'use', ], ]); $this->doTest($expected, $input); } public function provideFixWithUseCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'use_lambda', ], ]); $this->doTest($expected, $input); } public function provideFixWithUseLambdaCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'use_trait', ], ]); $this->doTest($expected, $input); } public function provideFixWithUseTraitCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'var', ], ]); $this->doTest($expected, $input); } public function provideFixWithVarCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'while', ], ]); $this->doTest($expected, $input); } public function provideFixWithWhileCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'yield', ], ]); $this->doTest($expected, $input); } public function provideFixWithYieldCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'yield_from', ], ]); $this->doTest($expected, $input); } public function provideFixWithYieldFromCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'php_open', ], ]); $this->doTest($expected, $input); } public function provideFixWithPhpOpenCases(): array { return [ [ 'fixer->configure([ 'constructs' => [ 'comment', 'php_doc', ], ]); $this->doTest($expected, $input); } public function provideCommentsCases(): \Generator { yield [ ' [ 'fixer->configure([ 'constructs' => [ 'namespace', ], ]); $this->doTest($expected, $input); } public function provideWithNamespaceCases(): iterable { yield 'simple' => [ ' [ ' [ ' [ ' [ ' [ 'doTest($expected, $input); } public function provideFix80Cases(): \Generator { yield 'match 1' => [ ' "Same for 1 and 2", };', ' "Same for 1 and 2", };', ]; yield 'match 2' => [ ' "Same for 1 and 2", };', ' "Same for 1 and 2", };', ]; yield 'constructor property promotion' => [ ' [ ' [ 'doTest($expected, $input); } public function provideFix81Cases(): \Generator { yield 'readonly' => [ ' [ ' [ '