diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 15cd9324da3..97e0dc6e7c8 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -21,7 +21,7 @@ parameters: - message: '#^Method PhpCsFixer\\Tests\\.+::provide.+Cases\(\) return type has no value type specified in iterable type iterable\.$#' path: tests - count: 1113 + count: 1102 - message: '#Call to static method .+ with .+ will always evaluate to true.$#' diff --git a/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php b/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php index 25729d53afb..a0255086a0e 100644 --- a/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php +++ b/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php @@ -27,10 +27,13 @@ final class NoAliasFunctionsFixerTest extends AbstractFixerTestCase { /** + * @param array $configuration + * * @dataProvider provideFixCases */ - public function testFix(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null, array $configuration = []): void { + $this->fixer->configure($configuration); $this->doTest($expected, $input); } @@ -98,21 +101,7 @@ public function is_integer($a) } }', ]; - } - - /** - * @param array $configuration - * - * @dataProvider provideFixWithConfigurationCases - */ - public function testFixWithConfiguration(string $expected, ?string $input, array $configuration): void - { - $this->fixer->configure($configuration); - $this->doTest($expected, $input); - } - public static function provideFixWithConfigurationCases(): iterable - { yield '@internal' => [ ' $configuration + * + * @dataProvider provideFixCases */ - public function testFixEchoToPrint(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null, array $configuration = []): void { - $this->fixer->configure(['use' => 'print']); + $this->fixer->configure($configuration); $this->doTest($expected, $input); } - public static function provideFixEchoToPrintCases(): iterable + /** + * @return iterable + */ + public static function provideFixCases(): iterable { yield [ ' 'print'], ]; yield [ ' 'print'], ]; yield [ ' 'print'], ]; // `echo` can take multiple parameters (although such usage is rare) while `print` can take only one argument, @@ -62,6 +73,8 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ @@ -71,6 +84,7 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ @@ -80,6 +94,7 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ @@ -89,6 +104,7 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ @@ -98,6 +114,7 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ @@ -107,6 +124,7 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ @@ -116,11 +134,13 @@ public static function provideFixEchoToPrintCases(): iterable ' 'print'], ]; yield [ "...", "...", + ['use' => 'print'], ]; yield [ @@ -136,47 +156,45 @@ public static function provideFixEchoToPrintCases(): iterable } echo "bar"; ', + ['use' => 'print'], ]; yield [ '', + null, + ['use' => 'print'], ]; foreach (self::getCodeSnippetsToConvertBothWays() as $codeSnippet) { yield [ sprintf($codeSnippet, 'print'), sprintf($codeSnippet, 'echo'), + ['use' => 'print'], ]; } - } - /** - * @dataProvider provideFixPrintToEchoCases - */ - public function testFixPrintToEcho(string $expected, ?string $input = null): void - { - $this->fixer->configure(['use' => 'echo']); - $this->doTest($expected, $input); - } - - public static function provideFixPrintToEchoCases(): iterable - { yield [ ' 'echo'], ]; yield [ ' 'echo'], ]; yield [ ' 'echo'], ]; // https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/1502#issuecomment-156436229 @@ -184,6 +202,8 @@ public static function provideFixPrintToEchoCases(): iterable ' 'echo'], ]; // echo has no return value while print has a return value of 1 so it can be used in expressions. @@ -192,12 +212,16 @@ public static function provideFixPrintToEchoCases(): iterable ' 'echo'], ]; yield [ ' 'echo'], ]; yield [ @@ -214,6 +238,8 @@ function testFunction() { switch(print(\'a\')) {} if (1 === print($a)) {} ', + null, + ['use' => 'echo'], ]; yield [ @@ -225,6 +251,7 @@ function testFunction() { some_function_call(); print "test"; ', + ['use' => 'echo'], ]; yield [ @@ -234,6 +261,7 @@ function testFunction() { ' 'echo'], ]; yield [ @@ -243,6 +271,7 @@ function testFunction() { ' 'echo'], ]; yield [ @@ -252,6 +281,7 @@ function testFunction() { ' 'echo'], ]; yield [ @@ -261,6 +291,7 @@ function testFunction() { ' 'echo'], ]; yield [ @@ -270,6 +301,7 @@ function testFunction() { ' 'echo'], ]; yield [ @@ -285,17 +317,19 @@ function testFunction() { } print "bar"; ', + ['use' => 'echo'], ]; foreach (self::getCodeSnippetsToConvertBothWays() as $codeSnippet) { yield [ sprintf($codeSnippet, 'echo'), sprintf($codeSnippet, 'print'), + ['use' => 'echo'], ]; } } - public function testDefaultConfig(): void + public function testConfigure(): void { $this->fixer->configure([]); @@ -305,9 +339,9 @@ public function testDefaultConfig(): void /** * @param array $wrongConfig * - * @dataProvider provideWrongConfigCases + * @dataProvider provideInvalidConfigurationCases */ - public function testWrongConfig(array $wrongConfig, string $expectedMessage): void + public function testInvalidConfiguration(array $wrongConfig, string $expectedMessage): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches($expectedMessage); @@ -315,7 +349,7 @@ public function testWrongConfig(array $wrongConfig, string $expectedMessage): vo $this->fixer->configure($wrongConfig); } - public static function provideWrongConfigCases(): iterable + public static function provideInvalidConfigurationCases(): iterable { yield [ ['a' => 'b'], diff --git a/tests/Fixer/Alias/PowToExponentiationFixerTest.php b/tests/Fixer/Alias/PowToExponentiationFixerTest.php index 2572fe7cda7..ed5be8eeda7 100644 --- a/tests/Fixer/Alias/PowToExponentiationFixerTest.php +++ b/tests/Fixer/Alias/PowToExponentiationFixerTest.php @@ -274,6 +274,22 @@ public function &pow($a, $b); 'doTest($expected); - } - - public static function provideNotFixCases(): iterable - { - yield [ - ' $configuration + * + * @dataProvider provideInvalidConfigurationCases + */ + public function testInvalidConfiguration(string $message, array $configuration): void { $this->expectException(InvalidFixerConfigurationException::class); - $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Function "is_null" is not handled by the fixer\.$#'); + $this->expectExceptionMessage($message); - $this->fixer->configure(['replacements' => ['is_null' => 'random_int']]); + $this->fixer->configure($configuration); } - public function testConfigureCheckReplacementType(): void + public static function provideInvalidConfigurationCases(): iterable { - $this->expectException(InvalidFixerConfigurationException::class); - $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "null" given\.$#'); + yield 'not supported function' => [ + '[random_api_migration] Invalid configuration: Function "is_null" is not handled by the fixer.', + ['replacements' => ['is_null' => 'random_int']], + ]; - $this->fixer->configure(['replacements' => ['rand' => null]]); + yield 'wrong replacement' => [ + '[random_api_migration] Invalid configuration: Replacement for function "rand" must be a string, "null" given.', + ['replacements' => ['rand' => null]], + ]; } public function testConfigure(): void diff --git a/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php b/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php index 20eb5aef752..b9f1e24ae9f 100644 --- a/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php +++ b/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php @@ -35,114 +35,259 @@ public function testInvalidConfiguration(): void $this->fixer->configure(['a' => 1]); } - public function testFixWithDefaultConfiguration(): void - { - $this->fixer->configure([]); - $this->doTest( - ' $configuration + * + * @dataProvider provideFixCases */ - public function testFixLongSyntax(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null, array $configuration = []): void { - $this->fixer->configure(['syntax' => 'long']); + $this->fixer->configure($configuration); $this->doTest($expected, $input); } - public static function provideFixLongSyntaxCases(): iterable - { - yield [' true) : array("f" => false)));', ' true] : ["f" => false])];']; - - yield [' [$x, $y]) {}']; - } - /** - * @dataProvider provideFixShortSyntaxCases + * @return iterable */ - public function testFixShortSyntax(string $expected, ?string $input = null): void - { - $this->fixer->configure(['syntax' => 'short']); - $this->doTest($expected, $input); - } - - public static function provideFixShortSyntaxCases(): iterable + public static function provideFixCases(): iterable { - yield [' true] : ["f" => false])];', ' true) : array("f" => false)));']; - - yield [' [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' true) : array("f" => false)));', + ' true] : ["f" => false])];', + ['syntax' => 'long'], ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' 'long'], + ]; + + yield [ + ' [$x, $y]) {}', + null, + ['syntax' => 'long'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' true] : ["f" => false])];', + ' true) : array("f" => false)));', + ['syntax' => 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; + + yield [ + ' 'short'], + ]; } } diff --git a/tests/Fixer/Basic/NoTrailingCommaInSinglelineFixerTest.php b/tests/Fixer/Basic/NoTrailingCommaInSinglelineFixerTest.php index 8d6d8ee23a6..4155d4d59fe 100644 --- a/tests/Fixer/Basic/NoTrailingCommaInSinglelineFixerTest.php +++ b/tests/Fixer/Basic/NoTrailingCommaInSinglelineFixerTest.php @@ -24,13 +24,19 @@ final class NoTrailingCommaInSinglelineFixerTest extends AbstractFixerTestCase { /** + * @param array $configuration + * * @dataProvider provideFixCases */ - public function testFix(string $expected, ?string $input = null): void + 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 [ @@ -47,93 +53,95 @@ public static function provideFixCases(): iterable 'fixer->configure(['elements' => ['arguments']]); - $this->doTest($expected, $input); - } - - public static function provideFixNoTrailingCommaInSinglelineFunctionCallCases(): iterable - { yield 'simple var' => [ ' ['arguments']], ]; yield '&' => [ ' ['arguments']], ]; yield 'open' => [ ' ['arguments']], ]; yield '=' => [ ' ['arguments']], ]; yield '.' => [ ' ['arguments']], ]; yield '(' => [ ' ['arguments']], ]; yield '\\' => [ ' ['arguments']], ]; yield 'A\\' => [ ' ['arguments']], ]; yield '\A\\' => [ ' ['arguments']], ]; yield ';' => [ ' ['arguments']], ]; yield '}' => [ ' ['arguments']], ]; yield 'test method call' => [ 'abc($a);', 'abc($a,);', + ['elements' => ['arguments']], ]; yield 'nested call' => [ 'abc($a,foo(1));', 'abc($a,foo(1,));', + ['elements' => ['arguments']], ]; yield 'wrapped' => [ 'getOutput(1);', 'getOutput(1,);', + ['elements' => ['arguments']], ]; yield 'dynamic function and method calls' => [ '$a(1); $c("");', '$a(1,); $c("",);', + ['elements' => ['arguments']], ]; yield 'static function call' => [ @@ -145,16 +153,19 @@ public static function provideFixNoTrailingCommaInSinglelineFunctionCallCases(): unset($foo->bar,); $b = isset($foo->bar,); ', + ['elements' => ['arguments']], ]; yield 'unset' => [ ' ['arguments']], ]; yield 'anonymous_class construction' => [ ' ['arguments']], ]; yield 'array/property access call' => [ @@ -194,6 +205,7 @@ public static function provideFixNoTrailingCommaInSinglelineFunctionCallCases(): $$e(2,); $f(0,)(1,); $g["e"](1,); // foo', + ['elements' => ['arguments']], ]; yield 'do not fix' => [ @@ -221,77 +233,51 @@ function foo1(string $param = null ): void { } ;', + null, + ['elements' => ['arguments']], ]; - } - /** - * @dataProvider provideFix80NoTrailingCommaInSinglelineFunctionCallFixerCases - * - * @requires PHP 8.0 - */ - public function testFix80NoTrailingCommaInSinglelineFunctionCallFixer(string $expected, string $input = null): void - { - $this->doTest($expected, $input); - } - - public static function provideFix80NoTrailingCommaInSinglelineFunctionCallFixerCases(): iterable - { yield [ - ' ['array']], ]; - } - /** - * @dataProvider provideFix81NoTrailingCommaInSinglelineFunctionCallFixerCases - * - * @requires PHP 8.1 - */ - public function testFix81NoTrailingCommaInSinglelineFunctionCallFixer(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public static function provideFix81NoTrailingCommaInSinglelineFunctionCallFixerCases(): iterable - { yield [ - 'method(1); strlen(...);', - 'method(1,); strlen(...);', + ' ['array']], ]; - } - - /** - * @dataProvider provideFixNoTrailingCommaInSinglelineArrayFixerCases - */ - public function testFixNoTrailingCommaInSinglelineArrayFixer(string $expected, ?string $input = null): void - { - $this->fixer->configure(['elements' => ['array']]); - - $this->doTest($expected, $input); - } - - public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): iterable - { - yield [' ['array']], ]; - yield [" ['array']], + ]; - yield [" ['array']], + ]; - yield [" ['array']], + ]; - yield [" ['array']], + ]; yield [ ' ['array']], ]; yield [ @@ -308,6 +296,8 @@ public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): i foo TWIG , $twig, );', + null, + ['elements' => ['array']], ]; yield [ @@ -316,6 +306,8 @@ public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): i foo TWIG , $twig, );', + null, + ['elements' => ['array']], ]; yield [ @@ -325,26 +317,64 @@ public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): i foo TWIG , $twig, );', + null, + ['elements' => ['array']], ]; // Short syntax - yield [' ['array']], + ]; - yield [' ['array']], + ]; - yield [' ['array']], + ]; - yield [' ['array']], + ]; - yield [" ['array']], + ]; - yield [" ['array']], + ]; - yield [' ['array']], + ]; - yield [' ['array']], + ]; - yield [' ['array']], + ]; yield [ ' ['array']], ]; yield [ @@ -361,6 +393,8 @@ public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): i foo TWIG , $twig, ];', + null, + ['elements' => ['array']], ]; yield [ @@ -369,6 +403,8 @@ public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): i foo TWIG , $twig, ];', + null, + ['elements' => ['array']], ]; yield [ @@ -378,31 +414,22 @@ public static function provideFixNoTrailingCommaInSinglelineArrayFixerCases(): i foo TWIG , $twig, ];', + null, + ['elements' => ['array']], ]; yield [ ' ['array']], ]; yield [ ' ['array']], ]; - } - - /** - * @dataProvider provideFixNoTrailingCommaInListCallFixerCases - */ - public function testFixNoTrailingCommaInListCallFixer(string $expected, ?string $input = null): void - { - $this->fixer->configure(['elements' => ['array_destructuring']]); - $this->doTest($expected, $input); - } - - public static function provideFixNoTrailingCommaInListCallFixerCases(): iterable - { yield [ ' ['array_destructuring']], ]; yield [ @@ -429,6 +457,8 @@ public static function provideFixNoTrailingCommaInListCallFixerCases(): iterable ,# # ) = $a;', + null, + ['elements' => ['array_destructuring']], ]; yield [ @@ -448,6 +478,47 @@ public static function provideFixNoTrailingCommaInListCallFixerCases(): iterable [$a11 , $b , ] = foo(); [$a12, /* $b */, $c, ] = foo(); ', + ['elements' => ['array_destructuring']], + ]; + } + + /** + * @dataProvider provideFix80Cases + * + * @requires PHP 8.0 + */ + public function testFix80(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public static function provideFix80Cases(): iterable + { + yield [ + 'doTest($expected, $input); + } + + public static function provideFix81Cases(): iterable + { + yield [ + 'method(1); strlen(...);', + 'method(1,); strlen(...);', ]; } } diff --git a/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php b/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php index 8d648316638..b5cf3fe880e 100644 --- a/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php +++ b/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php @@ -26,34 +26,25 @@ final class NonPrintableCharacterFixerTest extends AbstractFixerTestCase { /** + * @param array $configuration + * * @dataProvider provideFixCases */ - public function testFix(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null, array $configuration = []): void { - $this->fixer->configure([ - 'use_escape_sequences_in_strings' => false, - ]); - + $this->fixer->configure($configuration); $this->doTest($expected, $input); } /** - * @dataProvider provideFixCases + * @return iterable */ - public function testFixWithoutEscapeSequences(string $expected, ?string $input = null): void - { - $this->fixer->configure([ - 'use_escape_sequences_in_strings' => false, - ]); - - $this->doTest($expected, $input); - } - public static function provideFixCases(): iterable { yield [ ' false], ]; yield [ @@ -66,6 +57,7 @@ public static function provideFixCases(): iterable pack('H*', 'e2808b'). pack('H*', 'e2808b'). 'Hello World !";', + ['use_escape_sequences_in_strings' => false], ]; yield [ @@ -75,6 +67,7 @@ public static function provideFixCases(): iterable ' false], ]; yield [ @@ -96,54 +89,51 @@ function f(string $p) { echo $p; }', + ['use_escape_sequences_in_strings' => false], ]; yield [ ' false], ]; yield [ 'abc', 'a'.pack('H*', 'e2808b').'bc', + ['use_escape_sequences_in_strings' => false], ]; yield [ ' false], ]; yield [ ' false], ]; yield [ ' false], ]; yield [ ' false], ]; yield [ ' false], ]; - } - /** - * @dataProvider provideFixWithEscapeSequencesInStringsCases - */ - public function testFixWithEscapeSequencesInStrings(string $expected, ?string $input = null): void - { - $this->fixer->configure([ - 'use_escape_sequences_in_strings' => true, - ]); - - $this->doTest($expected, $input); - } - - public static function provideFixWithEscapeSequencesInStringsCases(): iterable - { yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ @@ -189,6 +185,8 @@ function f(string $p) FooBar\ TXT; ', + null, + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -200,6 +198,7 @@ function f(string $p) Foo'.pack('H*', 'e2808b').'Bar TXT; ', + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -211,6 +210,7 @@ function f(string $p) Foo'.pack('H*', 'e2808b').'Bar TXT; ', + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -222,10 +222,13 @@ function f(string $p) Foo'.pack('H*', 'e2808b').' Bar \n \ $variableToEscape TXT; ', + ['use_escape_sequences_in_strings' => true], ]; yield [ ' true], ]; yield [ @@ -240,6 +243,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -254,6 +258,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -274,6 +279,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -288,6 +294,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -302,6 +309,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -316,6 +324,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -330,6 +339,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -344,6 +354,7 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ @@ -358,11 +369,13 @@ function f(string $p) , pack('H*', 'e2808b') ), + ['use_escape_sequences_in_strings' => true], ]; yield [ " true], ]; } } diff --git a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php index ecd3382cb2d..9dc8ab31cd1 100644 --- a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php @@ -34,4 +34,20 @@ public function testFunctionIsDeprecatedProperly(): void $fixer->getSuccessorsNames(), ); } + + /** + * @dataProvider provideFixCases + */ + public function testFix(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + /** + * @return iterable + */ + public static function provideFixCases(): iterable + { + yield from NativeTypeDeclarationCasingFixerTest::provideFixCases(); + } } diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index a5333fddfd3..522ebd26fbf 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -372,6 +372,74 @@ final public function testFixerConfigurationDefinitions(): void } } + final public function testProperMethodNaming(): void + { + if ($this->fixer instanceof DeprecatedFixerInterface) { + self::markTestSkipped('Not worth refactoring tests for deprecated fixers.'); + } + + $exceptionGroup = [ + 'Casing', + 'CastNotation', + 'ClassNotation', + 'ClassUsage', + 'Comment', + 'ConstantNotation', + 'ControlStructure', + 'DoctrineAnnotation', + 'FunctionNotation', + 'Import', + 'LanguageConstruct', + 'ListNotation', + 'NamespaceNotation', + 'Naming', + 'Operator', + 'PhpTag', + 'PhpUnit', + 'Phpdoc', + 'ReturnNotation', + 'Semicolon', + 'Strict', + 'StringNotation', + 'Whitespace', + ]; + + $fixerGroup = explode('\\', static::class)[3]; + + if (\in_array($fixerGroup, $exceptionGroup, true)) { + self::markTestSkipped('Not covered yet.'); + } + + self::assertTrue(method_exists($this, 'testFix'), 'Method testFix does not exist.'); + self::assertTrue(method_exists($this, 'provideFixCases'), 'Method provideFixCases does not exist.'); + + $names = ['Fix', 'FixPre80', 'Fix80', 'Fix81', 'Fix82', 'Fix83', 'InvalidConfiguration']; + $methodNames = ['testConfigure']; + foreach ($names as $name) { + $methodNames[] = 'test'.$name; + $methodNames[] = 'provide'.$name.'Cases'; + } + + $class = new \ReflectionObject($this); + + $extraMethods = []; + foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { + if ($method->getDeclaringClass()->getName() !== $class->getName()) { + continue; + } + if (\in_array($method->getName(), $methodNames, true)) { + continue; + } + $extraMethods[] = $method->getName(); + } + + self::assertSame( + [], + $extraMethods, + sprintf('Methods "%s" should not be present.', implode('". "', $extraMethods)), + ); + } + protected function createFixer(): AbstractFixer { $fixerClassName = preg_replace('/^(PhpCsFixer)\\\\Tests(\\\\.+)Test$/', '$1$2', static::class);