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