diff --git a/doc/ruleSets/PhpCsFixer.rst b/doc/ruleSets/PhpCsFixer.rst index 46f79b6b31f..4e08b069938 100644 --- a/doc/ruleSets/PhpCsFixer.rst +++ b/doc/ruleSets/PhpCsFixer.rst @@ -12,7 +12,7 @@ Rules - `array_indentation <./../rules/whitespace/array_indentation.rst>`_ - `blank_line_before_statement <./../rules/whitespace/blank_line_before_statement.rst>`_ config: - ``['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'include', 'include_once', 'phpdoc', 'require', 'require_once', 'return', 'switch', 'throw', 'try']]`` + ``['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'include', 'include_once', 'phpdoc', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'yield']]`` - `combine_consecutive_issets <./../rules/language_construct/combine_consecutive_issets.rst>`_ - `combine_consecutive_unsets <./../rules/language_construct/combine_consecutive_unsets.rst>`_ - `empty_loop_body <./../rules/control_structure/empty_loop_body.rst>`_ diff --git a/doc/rules/whitespace/blank_line_before_statement.rst b/doc/rules/whitespace/blank_line_before_statement.rst index 2c46e07d4a8..e3a81d4e4fa 100644 --- a/doc/rules/whitespace/blank_line_before_statement.rst +++ b/doc/rules/whitespace/blank_line_before_statement.rst @@ -235,7 +235,7 @@ The rule is part of the following rule sets: @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``blank_line_before_statement`` rule with the config below: - ``['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'include', 'include_once', 'phpdoc', 'require', 'require_once', 'return', 'switch', 'throw', 'try']]`` + ``['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'include', 'include_once', 'phpdoc', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'yield']]`` @Symfony Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``blank_line_before_statement`` rule with the config below: diff --git a/src/Indicator/PhpUnitTestCaseIndicator.php b/src/Indicator/PhpUnitTestCaseIndicator.php index cdccb8eda90..7650e706626 100644 --- a/src/Indicator/PhpUnitTestCaseIndicator.php +++ b/src/Indicator/PhpUnitTestCaseIndicator.php @@ -72,6 +72,7 @@ public function findPhpUnitClasses(Tokens $tokens): \Generator } $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex); + yield [$startIndex, $endIndex]; } } diff --git a/src/RuleSet/Sets/PhpCsFixerSet.php b/src/RuleSet/Sets/PhpCsFixerSet.php index 83e8b6f9643..bd2a3a8e7a7 100644 --- a/src/RuleSet/Sets/PhpCsFixerSet.php +++ b/src/RuleSet/Sets/PhpCsFixerSet.php @@ -45,6 +45,7 @@ public function getRules(): array 'switch', 'throw', 'try', + 'yield', ], ], 'combine_consecutive_issets' => true, diff --git a/tests/Console/Command/HelpCommandTest.php b/tests/Console/Command/HelpCommandTest.php index ac2c01649da..d4b540ee9af 100644 --- a/tests/Console/Command/HelpCommandTest.php +++ b/tests/Console/Command/HelpCommandTest.php @@ -39,15 +39,25 @@ public function testToString(string $expected, $input): void public function provideToStringCases(): \Generator { yield ["['a' => 3, 'b' => 'c']", ['a' => 3, 'b' => 'c']]; + yield ['[[1], [2]]', [[1], [2]]]; + yield ['[0 => [1], \'a\' => [2]]', [[1], 'a' => [2]]]; + yield ['[1, 2, \'foo\', null]', [1, 2, 'foo', null]]; + yield ['[1, 2]', [1, 2]]; + yield ['[]', []]; + yield ['1.5', 1.5]; + yield ['false', false]; + yield ['true', true]; + yield ['1', 1]; + yield ["'foo'", 'foo']; } @@ -64,8 +74,11 @@ public function testGetDisplayableAllowedValues($expected, FixerOptionInterface public function provideGetDisplayableAllowedValuesCases(): \Generator { yield [null, new FixerOption('foo', 'bar', false, null, ['int'], [])]; + yield [['A', 'B', 'x', 'z'], new FixerOption('foo', 'bar', false, null, ['string'], ['z', 'x', 'B', 'A'])]; + yield [[0, 3, 9], new FixerOption('foo', 'bar', false, null, ['int'], [0, 3, 9, static function (): void {}])]; + yield [null, new FixerOption('foo', 'bar')]; } } diff --git a/tests/DocBlock/AnnotationTest.php b/tests/DocBlock/AnnotationTest.php index 540888b8dd9..a3dccce5374 100644 --- a/tests/DocBlock/AnnotationTest.php +++ b/tests/DocBlock/AnnotationTest.php @@ -555,7 +555,9 @@ public function provideTypeExpressionCases(): \Generator $useTraversable = new NamespaceUseAnalysis('Traversable', 'Traversable', false, 0, 999, NamespaceUseAnalysis::TYPE_CLASS); yield ['* @param array|Traversable $foo', null, [], 'iterable']; + yield ['* @param array|Traversable $foo', $appNamespace, [], null]; + yield ['* @param array|Traversable $foo', $appNamespace, [$useTraversable], 'iterable']; } @@ -571,23 +573,41 @@ public function testGetVariableName(string $line, ?string $expectedVariableName) public function provideGetVariableCases(): \Generator { yield ['* @param int $foo', '$foo']; + yield ['* @param int $foo some description', '$foo']; + yield ['/** @param int $foo*/', '$foo']; + yield ['* @param int', null]; + yield ['* @var int $foo', '$foo']; + yield ['* @var int $foo some description', '$foo']; + yield ['/** @var int $foo*/', '$foo']; + yield ['* @var int', null]; + yield ['* @param $foo', '$foo']; + yield ['* @param &$foo', '$foo']; + yield ['* @param & $foo', '$foo']; + yield ['* @param int &$foo', '$foo']; + yield ['* @param int & $foo', '$foo']; + yield ['* @param int ...$foo', '$foo']; + yield ['* @param int ... $foo', '$foo']; + yield ['* @param int&...$foo', '$foo']; + yield ['* @param int &...$foo', '$foo']; + yield ['* @param int & ...$foo', '$foo']; + yield ['* @param int & ... $foo', '$foo']; } } diff --git a/tests/DocBlock/TypeExpressionTest.php b/tests/DocBlock/TypeExpressionTest.php index 7d9e003d515..64dd2717cef 100644 --- a/tests/DocBlock/TypeExpressionTest.php +++ b/tests/DocBlock/TypeExpressionTest.php @@ -40,49 +40,93 @@ public function testGetTypes(string $typesExpression, array $expectedTypes): voi public function provideGetTypesCases(): \Generator { yield ['int', ['int']]; + yield ['Foo[][]', ['Foo[][]']]; + yield ['int[]', ['int[]']]; + yield ['int[]|null', ['int[]', 'null']]; + yield ['int[]|null|?int|array', ['int[]', 'null', '?int', 'array']]; + yield ['null|Foo\Bar|\Baz\Bax|int[]', ['null', 'Foo\Bar', '\Baz\Bax', 'int[]']]; + yield ['gen', ['gen']]; + yield ['int|gen', ['int', 'gen']]; + yield ['\int|\gen<\int, \bool>', ['\int', '\gen<\int, \bool>']]; + yield ['gen', ['gen']]; + yield ['gen', ['gen']]; + yield ['gen', ['gen']]; + yield ['gen>', ['gen>']]; + yield ['gen>', ['gen>']]; + yield ['null|gen>|int|string[]', ['null', 'gen>', 'int', 'string[]']]; + yield ['null|gen>|int|array|string[]', ['null', 'gen>', 'int', 'array', 'string[]']]; + yield ['this', ['this']]; + yield ['@this', ['@this']]; + yield ['$SELF|int', ['$SELF', 'int']]; + yield ['array', ['array']]; + yield ['Collection, Foo>', ['Collection, Foo>']]; + yield ['int | string', ['int', 'string']]; + yield ['Foo::*', ['Foo::*']]; + yield ['Foo::A', ['Foo::A']]; + yield ['Foo::A|Foo::B', ['Foo::A', 'Foo::B']]; + yield ['Foo::A*', ['Foo::A*']]; + yield ['array|null', ['array', 'null']]; + yield ['null|true|false|1|1.5|\'a\'|"b"', ['null', 'true', 'false', '1', '1.5', "'a'", '"b"']]; + yield ['int | "a" | A, E>', ['int', '"a"', 'A, E>']]; + yield ['class-string', ['class-string']]; + yield ['A&B', ['A', 'B']]; + yield ['A & B', ['A', 'B']]; + yield ['array{1: bool, 2: bool}', ['array{1: bool, 2: bool}']]; + yield ['array{a: int|string, b?: bool}', ['array{a: int|string, b?: bool}']]; + yield ['array{\'a\': "a", "b"?: \'b\'}', ['array{\'a\': "a", "b"?: \'b\'}']]; + yield ['array { a : int | string , b ? : A }', ['array { a : int | string , b ? : A }']]; + yield ['callable(string)', ['callable(string)']]; + yield ['callable(string): bool', ['callable(string): bool']]; + yield ['callable(array, array): bool', ['callable(array, array): bool']]; + yield ['array', ['array']]; + yield ['callable(string): callable(int)', ['callable(string): callable(int)']]; + yield ['callable(string) : callable(int) : bool', ['callable(string) : callable(int) : bool']]; + yield ['TheCollection|string[]|null', ['TheCollection', 'string[]', 'null']]; + yield ['Closure(string)', ['Closure(string)']]; + yield ['array < int , callable ( string ) : bool >', ['array < int , callable ( string ) : bool >']]; } @@ -98,7 +142,9 @@ public function testGetTypesGlue(string $expectedTypesGlue, string $typesExpress public static function provideGetTypesGlueCases(): iterable { yield ['|', 'string']; // for backward behaviour + yield ['|', 'bool|string']; + yield ['&', 'Foo&Bar']; } @@ -122,55 +168,103 @@ public function provideCommonTypeCases(): \Generator $useObjectAsTraversable = new NamespaceUseAnalysis('Foo', 'Traversable', false, 0, 0, NamespaceUseAnalysis::TYPE_CLASS); yield ['true', 'bool']; + yield ['false', 'bool']; + yield ['bool', 'bool']; + yield ['int', 'int']; + yield ['float', 'float']; + yield ['string', 'string']; + yield ['array', 'array']; + yield ['object', 'object']; + yield ['self', 'self']; + yield ['static', 'static']; + yield ['bool[]', 'array']; + yield ['int[]', 'array']; + yield ['float[]', 'array']; + yield ['string[]', 'array']; + yield ['array[]', 'array']; + yield ['bool[][]', 'array']; + yield ['int[][]', 'array']; + yield ['float[][]', 'array']; + yield ['string[][]', 'array']; + yield ['array[][]', 'array']; + yield ['array|iterable', 'iterable']; + yield ['iterable|array', 'iterable']; + yield ['array|Traversable', 'iterable']; + yield ['array|\Traversable', 'iterable']; + yield ['array|Traversable', 'iterable', $globalNamespace]; + yield ['iterable|Traversable', 'iterable']; + yield ['array', 'array']; + yield ['array', 'array']; + yield ['iterable', 'iterable']; + yield ['iterable', 'iterable']; + yield ['\Traversable', '\Traversable']; + yield ['Traversable', 'Traversable']; + yield ['Collection', 'Collection']; + yield ['Collection', 'Collection']; + yield ['array|iterable', 'iterable']; + yield ['int[]|string[]', 'array']; + yield ['int|null', 'int']; + yield ['null|int', 'int']; + yield ['void', 'void']; + yield ['never', 'never']; + yield ['array|Traversable', 'iterable', null, [$useTraversable]]; + yield ['array|Traversable', 'iterable', $globalNamespace, [$useTraversable]]; + yield ['array|Traversable', 'iterable', $appNamespace, [$useTraversable]]; + yield ['self|static', 'self']; yield ['array|Traversable', null, null, [$useObjectAsTraversable]]; + yield ['array|Traversable', null, $globalNamespace, [$useObjectAsTraversable]]; + yield ['array|Traversable', null, $appNamespace, [$useObjectAsTraversable]]; + yield ['bool|int', null]; + yield ['string|bool', null]; + yield ['array|Collection', null]; } @@ -186,13 +280,19 @@ public function testAllowsNull(string $typesExpression, bool $expectNullAllowed) public function provideAllowsNullCases(): \Generator { yield ['null', true]; + yield ['mixed', true]; + yield ['null|mixed', true]; + yield ['int|bool|null', true]; + yield ['int|bool|mixed', true]; yield ['int', false]; + yield ['bool', false]; + yield ['string', false]; } @@ -216,74 +316,92 @@ public function provideSortTypesCases(): iterable 'int', 'int', ]; + yield 'simple' => [ 'int|bool', 'bool|int', ]; + yield 'simple in generic' => [ 'array', 'array', ]; + yield 'generic with multiple types' => [ 'array', 'array', ]; + yield 'simple in array shape with int key' => [ 'array{0: int|bool}', 'array{0: bool|int}', ]; + yield 'simple in array shape with string key' => [ 'array{"foo": int|bool}', 'array{"foo": bool|int}', ]; + yield 'simple in array shape with multiple keys' => [ 'array{0: int|bool, "foo": int|bool}', 'array{0: bool|int, "foo": bool|int}', ]; + yield 'simple in callable argument' => [ 'callable(int|bool)', 'callable(bool|int)', ]; + yield 'callable with multiple arguments' => [ 'callable(int|bool, null|array)', 'callable(bool|int, array|null)', ]; + yield 'simple in callable return type' => [ 'callable(): string|float', 'callable(): float|string', ]; + yield 'simple in closure argument' => [ 'Closure(int|bool)', 'Closure(bool|int)', ]; + yield 'closure with multiple arguments' => [ 'Closure(int|bool, null|array)', 'Closure(bool|int, array|null)', ]; + yield 'simple in closure return type' => [ 'Closure(): string|float', 'Closure(): float|string', ]; + yield 'with multiple nesting levels' => [ 'array{0: Foo|Bar): Foo|Bar>}', 'array{0: Bar|float|string): Bar|Foo>|Foo}', ]; + yield 'nullable generic' => [ '?array', '?array', ]; + yield 'nullable callable' => [ '?callable(Foo|Bar): Foo|Bar', '?callable(Bar|Foo): Bar|Foo', ]; + yield 'nullable array shape' => [ '?array{0: Foo|Bar}', '?array{0: Bar|Foo}', ]; + yield 'simple types alternation' => [ 'array', 'array', ]; + yield 'nesty stuff' => [ 'array>>', 'array|Level2>&Level11>', diff --git a/tests/Fixer/Alias/MbStrFunctionsFixerTest.php b/tests/Fixer/Alias/MbStrFunctionsFixerTest.php index 9a8b5146a67..9e991e55d59 100644 --- a/tests/Fixer/Alias/MbStrFunctionsFixerTest.php +++ b/tests/Fixer/Alias/MbStrFunctionsFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null): void public function provideFixCases(): array { - $cases = [ + return [ ['doTest($expected, $input); - } - - public function provideFixPhp74Cases(): \Generator - { - yield [ - 'fixer->configure(['use' => 'print']); - $this->doTest($expected, $input); } @@ -152,7 +151,6 @@ public static function provideEchoToPrintFixNewCases(): \Generator public function testFixPrintToEcho(string $expected, ?string $input = null): void { $this->fixer->configure(['use' => 'echo']); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/Alias/PowToExponentiationFixerTest.php b/tests/Fixer/Alias/PowToExponentiationFixerTest.php index 3b4a23ce641..cd724f89824 100644 --- a/tests/Fixer/Alias/PowToExponentiationFixerTest.php +++ b/tests/Fixer/Alias/PowToExponentiationFixerTest.php @@ -222,6 +222,18 @@ public function &pow($a, $b); [ 'doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ - [ - 'doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ - [ - 'fixer->configure($config); - $this->doTest($expected, $input); } @@ -171,31 +170,15 @@ public function &rand(); null, ['replacements' => ['rand' => 'rand']], ], - ]; - } - - /** - * @requires PHP 7.3 - * @dataProvider provideFix73Cases - */ - public function testFix73(string $expected, string $input, array $config = []): void - { - $this->fixer->configure($config); - - $this->doTest($expected, $input); - } - - public function provideFix73Cases(): \Generator - { - yield [ - ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], - ]; - - yield [ - ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], + ], + [ + ' [ 'doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ 'null cast' => [ 'doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ [ ' null;', diff --git a/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php b/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php index d3c76c0efea..8065faba676 100644 --- a/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php +++ b/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php @@ -137,21 +137,6 @@ public function provideFixCases(): array TWIG , $twig, ];', ], - ]; - } - - /** - * @dataProvider provideFixPhp74Cases - * @requires PHP 7.4 - */ - public function testFixPhp74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ [ 'fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -137,22 +141,6 @@ public function provideFixCases(): array EOF );", ], - ]; - } - - /** - * @dataProvider provideFix73Cases - * @requires PHP 7.3 - */ - public function testFix73(string $expected, ?string $input = null, array $config = []): void - { - $this->fixer->configure($config); - $this->doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ [ " true], ], - ]; - } - - /** - * @dataProvider provideFixPhp74Cases - * @requires PHP 7.4 - */ - public function testFixPhp74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ [ 'doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ [ 'doTest($expected, $input); } @@ -47,19 +47,7 @@ public function provideFixCases(): \Generator 'doTest($expected, $input); - } - public static function provideFix74Cases(): \Generator - { yield [ '', ''], + [ + ' true;', + ' true;', + ], ]; } @@ -48,25 +52,6 @@ public function testHaltCompiler(): void $this->doTest('doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ - [ - ' true;', - ' true;', - ], - ]; - } - /** * @dataProvider provideFix80Cases * @requires PHP 8.0 diff --git a/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php b/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php index 625e3666a1d..3d52ae5498c 100644 --- a/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php +++ b/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php @@ -178,25 +178,12 @@ public function provideFixCases(): array [ 'doTest($expected, $input); - } - - public function provideFix74Cases(): \Generator - { - yield [ - '= 80000) { - static::markTestSkipped('PHP < 8.0 is required.'); - } - $this->doTest($expected, $input); } diff --git a/tests/Fixer/Casing/MagicMethodCasingFixerTest.php b/tests/Fixer/Casing/MagicMethodCasingFixerTest.php index a8c1cdca84a..22917934ce7 100644 --- a/tests/Fixer/Casing/MagicMethodCasingFixerTest.php +++ b/tests/Fixer/Casing/MagicMethodCasingFixerTest.php @@ -258,6 +258,11 @@ function __ISSET($bar){} // do not fix $a->__UnSet($foo); // fix ', ]; + + yield [ + '__invoke(1, );', + '__INVOKE(1, );', + ]; } /** @@ -333,17 +338,6 @@ function a() ]; } - /** - * @requires PHP 7.3 - */ - public function testFix73(): void - { - $this->doTest( - '__invoke(1, );', - '__INVOKE(1, );' - ); - } - /** * @requires PHP 8.0 */ diff --git a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php index 93888ad7e2a..9736b371093 100644 --- a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php @@ -162,21 +162,6 @@ public function getName() { } }', ], - ]; - } - - /** - * @requires PHP 7.3 - * @dataProvider provideFix73Cases - */ - public function testFix73(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ [ 'doTest($expected, $input); - } - - /** - * @dataProvider provideFixCases - * @requires PHP 7.4 */ public function testFix74(string $expected, ?string $input = null): void { @@ -44,7 +33,6 @@ public function testFix74(string $expected, ?string $input = null): void /** * @dataProvider provideFixDeprecatedCases - * @requires PHP 7.4 * @group legacy */ public function testFix74Deprecated(string $expected, ?string $input = null): void diff --git a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php index bbf258663bd..e579384f692 100644 --- a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php +++ b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php @@ -169,6 +169,18 @@ public function &doubleval($a); 'doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ - [ - 'doTest($expected, $input); - } - - /** - * @dataProvider provideFixCases - * @requires PHP 7.4 */ public function testFix74(string $expected, ?string $input = null): void { @@ -44,7 +33,6 @@ public function testFix74(string $expected, ?string $input = null): void /** * @dataProvider provideFixDeprecatedCases - * @requires PHP 7.4 * @group legacy */ public function testFix74Deprecated(string $expected, ?string $input = null): void @@ -105,18 +93,22 @@ private function createCasesFor(string $from, string $to): \Generator sprintf(' [['method', 'property']]; + yield 'wrong key name' => [['methods' => 'one']]; + yield 'wrong key value' => [['method' => 'two']]; } diff --git a/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php b/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php index 82c30afab35..18084d81afd 100644 --- a/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php +++ b/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php @@ -54,7 +54,6 @@ public function testConfigureDefaultToFalse(): void public function testFixingAnonymousClasses(string $expected, string $input, array $config = []): void { $this->fixer->configure($config); - $this->doTest($expected, $input); } @@ -64,7 +63,6 @@ public function testFixingAnonymousClasses(string $expected, string $input, arra public function testFixingClasses(string $expected, string $input): void { $this->fixer->configure([]); - $this->doTest($expected, $input); } @@ -74,7 +72,6 @@ public function testFixingClasses(string $expected, string $input): void public function testFixingClassesWithConfig(string $expected, string $input, array $config): void { $this->fixer->configure($config); - $this->doTest($expected, $input); } @@ -84,7 +81,6 @@ public function testFixingClassesWithConfig(string $expected, string $input, arr public function testFixingInterfaces(string $expected, string $input): void { $this->fixer->configure([]); - $this->doTest($expected, $input); } @@ -94,7 +90,6 @@ public function testFixingInterfaces(string $expected, string $input): void public function testFixingTraits(string $expected, string $input): void { $this->fixer->configure([]); - $this->doTest($expected, $input); } @@ -587,7 +582,6 @@ public function test() public function testFix(string $expected, ?string $input = null): void { $this->fixer->configure([]); - $this->doTest($expected, $input); } @@ -624,22 +618,6 @@ public function provideFixCases(): array { }?>', ], - ]; - } - - /** - * @dataProvider providePHP73Cases - * @requires PHP 7.3 - */ - public function testFixPHP73(string $expected, ?string $input = null): void - { - $this->fixer->configure([]); - $this->doTest($expected, $input); - } - - public function providePHP73Cases(): array - { - return [ [ 'fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure([]); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php b/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php index c690075bbdd..1af1e277b21 100644 --- a/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php +++ b/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php @@ -276,38 +276,24 @@ public function provideFixCases(): array [ 'doTest($expected, $input); - } - - public function provideFix74Cases(): \Generator - { - yield [ - 'fixer->configure(['order' => ['use_trait'], 'sort_algorithm' => OrderedClassElementsFixer::SORT_ALPHA]); - $this->doTest( sprintf($template, $methodName2, $methodName1), sprintf($template, $methodName1, $methodName2) @@ -1321,8 +1321,11 @@ public function %s(){} public function provideWithConfigWithNoCandidateCases(): \Generator { yield ['z', '__construct']; + yield ['z', '__destruct']; + yield ['z', '__sleep']; + yield ['z', 'abc']; } diff --git a/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php b/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php index fe0f9cb5976..f0ee167644c 100644 --- a/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php +++ b/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php @@ -118,33 +118,18 @@ protected function bar() [ 'doTest($expected, $input); - } - - public function provideFix74Cases(): \Generator - { - yield [ - 'doTest($expected, $input); } - public function provideFixCases(): array + public function provideFixCases(): iterable { - return [ + yield from [ [ 'doTest($expected, $input); - } - - public function provideTestFix74Cases(): \Generator - { - yield [ - 'fixer->configure(['elements' => ['property', 'method', 'const']]); - $this->doTest( 'doTest($expected, $input); } - public function provideFix74Cases(): \Generator + public function provideFixCases(): \Generator { yield [ 'DateTime();']; + yield ['date_create();']; } } diff --git a/tests/Fixer/Comment/HeaderCommentFixerTest.php b/tests/Fixer/Comment/HeaderCommentFixerTest.php index 66f36f60d22..ec95c93c1dd 100644 --- a/tests/Fixer/Comment/HeaderCommentFixerTest.php +++ b/tests/Fixer/Comment/HeaderCommentFixerTest.php @@ -33,7 +33,6 @@ final class HeaderCommentFixerTest extends AbstractFixerTestCase public function testFix(array $configuration, string $expected, ?string $input = null): void { $this->fixer->configure($configuration); - $this->doTest($expected, $input); } @@ -746,7 +745,6 @@ public function testMessyWhitespaces(array $configuration, string $expected, ?st { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure($configuration); - $this->doTest($expected, $input); } @@ -769,21 +767,18 @@ public function provideMessyWhitespacesCases(): array public function testConfigurationUpdatedWithWhitespsacesConfig(): void { $this->fixer->configure(['header' => 'Foo']); - $this->doTest( "fixer->setWhitespacesConfig(new WhitespacesFixerConfig(' ', "\r\n")); - $this->doTest( "fixer->configure(['header' => 'Bar']); - $this->doTest( "fixer->configure(['strict' => true]); - $this->doTest( ' [ + 'doTest($expected); - } - - public function provideNoFix7Cases(): array - { - return [ - [ - 'doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ 'numeric literal separator' => [ ' true], - ]; - - yield [ - '[trailing_comma_in_multiline] Invalid configuration for env: "arguments" option can only be enabled with PHP 7.3+.', - ['elements' => [TrailingCommaInMultilineFixer::ELEMENTS_ARGUMENTS]], - ]; - } - yield [ '[trailing_comma_in_multiline] Invalid configuration for env: "parameters" option can only be enabled with PHP 8.0+.', ['elements' => [TrailingCommaInMultilineFixer::ELEMENTS_PARAMETERS]], @@ -67,8 +55,12 @@ public static function provideInvalidConfigurationCases(): \Generator /** * @dataProvider provideFixCases */ - public function testFix(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null, array $config = null): void { + if (null !== $config) { + $this->fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -397,23 +389,8 @@ function a() $a ) ) -) {}'], - ]; - } - - /** - * @dataProvider provideFix73Cases - * @requires PHP 7.3 - */ - public function testFix73(string $expected, ?string $input = null, array $config = []): void - { - $this->fixer->configure($config); - $this->doTest($expected, $input); - } - - public static function provideFix73Cases(): array - { - return [ +) {}', + ], [ "doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ [ 'fixer->configure($configuration); - $this->doTest($expected, $input); } @@ -364,23 +363,6 @@ function foo() /* bar */ ['', null, self::$configurationClosureSpacingNone], - ]; - } - - /** - * @dataProvider provideFix74Cases - * @requires PHP 7.4 - */ - public function test74(string $expected, ?string $input = null, array $configuration = []): void - { - $this->fixer->configure($configuration); - - $this->doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ [ ' null;', ' null;', @@ -446,7 +428,6 @@ public function provideFix74Cases(): array public function testFixPhp80(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php b/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php index 5a466ee997c..07c7e98f121 100644 --- a/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php @@ -185,21 +185,6 @@ public function provideFixCases(): array ], [''], - ]; - } - - /** - * @dataProvider provideFix74Cases - * @requires PHP 7.4 - */ - public function testFix74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ [ ' null;', ' null;', diff --git a/tests/Fixer/FunctionNotation/ImplodeCallFixerTest.php b/tests/Fixer/FunctionNotation/ImplodeCallFixerTest.php index c26e5c7a754..374107f47e6 100644 --- a/tests/Fixer/FunctionNotation/ImplodeCallFixerTest.php +++ b/tests/Fixer/FunctionNotation/ImplodeCallFixerTest.php @@ -36,11 +36,17 @@ public function testFix(string $expected, ?string $input = null): void public function provideFixCases(): \Generator { yield ["implode($foo);']; + yield ['doTest($expected, $input); - } - - public function provideFix73Cases(): \Generator - { yield [ 'fixer->configure($config); $this->doTest($expected, $input); } - public function provideFix56Cases(): \Generator + public function provideFix2Cases(): \Generator { yield [ 'fixer->configure($config); - $this->doTest($expected, $input); - } - public function provideFix73Cases(): \Generator - { yield [ <<<'EXPECTED' fixer->configure($config); - $this->doTest($expected, $input); - } - - public function provideFix74Cases(): \Generator - { yield [ 'fixer->configure($configuration); - $this->doTest($expected, $input); } @@ -585,17 +588,6 @@ public function & strlen($name) { } } - /** - * @requires PHP 7.3 - */ - public function testFix73(): void - { - $this->doTest( - 'doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ [ ' null;', ' null;', diff --git a/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php b/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php index d57f4f5b62b..f3a671f84c5 100644 --- a/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php +++ b/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php @@ -99,19 +99,7 @@ function sprintf($foo) { yield [ 'doTest($expected, $input); - } - public function provideFix73Cases(): \Generator - { yield 'trailing comma' => [ 'fixer->configure(['use_nullable_type_declaration' => false]); - $this->doTest($expected, $input); } @@ -343,7 +384,6 @@ public function testFixPhp74(string $expected, string $input): void public function testFixInversePhp74(string $expected, string $input): void { $this->fixer->configure(['use_nullable_type_declaration' => false]); - $this->doTest($expected, $input); } @@ -405,7 +445,6 @@ public function testFix80(string $expected, ?string $input = null): void public function testFixInverse80(string $expected, ?string $input = null): void { $this->fixer->configure(['use_nullable_type_declaration' => false]); - $this->doTest($expected, $input); } @@ -498,6 +537,7 @@ function foo2(?string &/*comment*/$param2 = null) {} ]; yield [$cases[0], $cases[1]]; + yield [$cases[1], $cases[0], ['use_nullable_type_declaration' => false]]; } diff --git a/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php index 2f74a0b1f38..5cecde812c5 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php @@ -34,7 +34,6 @@ public function testFix(string $expected, ?string $input = null, array $config = } $this->fixer->configure($config); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php index 9c26de19218..7cecadf4303 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php @@ -39,7 +39,6 @@ public function testFix(string $expected, ?string $input = null, ?int $versionSp } $this->fixer->configure($config); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php b/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php index af0aecf9d84..29817621f31 100644 --- a/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php +++ b/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php @@ -204,19 +204,7 @@ function call_user_func($foo){} 'doTest($expected, $input); - } - public function provideFix73Cases(): \Generator - { yield [ 'fixer->configure([]); - $this->doTest($expected, $input); } @@ -109,6 +108,10 @@ function foo8(int $a):string {} function foo9(int $a):string {} ', ], + [ + ' 1;', + ' 1;', + ], ]; } @@ -148,25 +151,6 @@ public function provideFixWithSpaceBeforeOneCases(): array ]; } - /** - * @dataProvider provideFixWithSpaceBeforeNonePhp74Cases - * @requires PHP 7.4 - */ - public function testFixWithDefaultConfigurationPhp74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixWithSpaceBeforeNonePhp74Cases(): array - { - return [ - [ - ' 1;', - ' 1;', - ], - ]; - } - /** * @dataProvider provideFix80Cases * @requires PHP 8.0 diff --git a/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php b/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php index 05f56749785..bda80a6b38c 100644 --- a/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php +++ b/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php @@ -26,7 +26,7 @@ final class StaticLambdaFixerTest extends AbstractFixerTestCase /** * @dataProvider provideFixCases */ - public function testFix(string $expected, string $input): void + public function testFix(string $expected, string $input = null): void { $this->doTest($expected, $input); } @@ -54,6 +54,73 @@ public function provideFixCases(): array ' null;$b=static fn() => null;', + ' null;$b=fn() => null;', + ], + [ + ' null;', + ' null;', + ], + [ + ' null;', + ' null;', + ], + [ + ' null; echo $this->foo();', + ' null; echo $this->foo();', + ], + [ + ' null ?> foo();', + ' null ?> foo();', + ], + [ + ' var_dump($this); + $a(); + } + } + ', + ], + [ + ' "bar"]) => [];', + ' "bar"]) => [];', + ], + [ + ' $item->getName(), + $this->getItems() + ); + } + }', + ' $item->getName(), + $this->getItems() + ); + } + }', + ], + [ + ' $item->getName(1, $this->foo()), + $this->getItems() + ); + } + }', + ], ]; } @@ -237,86 +304,4 @@ public function foo() ], ]; } - - /** - * @dataProvider provideFixPhp74Cases - * @requires PHP 7.4 - */ - public function testFixPhp74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ - [ - ' null;$b=static fn() => null;', - ' null;$b=fn() => null;', - ], - [ - ' null;', - ' null;', - ], - [ - ' null;', - ' null;', - ], - [ - ' null; echo $this->foo();', - ' null; echo $this->foo();', - ], - [ - ' null ?> foo();', - ' null ?> foo();', - ], - [ - ' var_dump($this); - $a(); - } - } - ', - ], - [ - ' "bar"]) => [];', - ' "bar"]) => [];', - ], - [ - ' $item->getName(), - $this->getItems() - ); - } - }', - ' $item->getName(), - $this->getItems() - ); - } - }', - ], - [ - ' $item->getName(1, $this->foo()), - $this->getItems() - ); - } - }', - ], - ]; - } } diff --git a/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php b/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php index 197158497fe..e08803c54bf 100644 --- a/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php +++ b/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php @@ -25,17 +25,8 @@ */ final class UseArrowFunctionsFixerTest extends AbstractFixerTestCase { - /** - * @requires PHP <7.4 - */ - public function testDoNotFix(): void - { - $this->doTest('doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ [ ' null;', ], @@ -266,21 +251,37 @@ public static function provideMethodWillNotCauseSyntaxErrorCases(): iterable { // List: https://www.php.net/manual/en/language.oop5.magic.php yield ['__construct']; + yield ['__destruct']; + yield ['__call', 2]; + yield ['__callStatic', 2, true]; + yield ['__get', 1]; + yield ['__set', 2]; + yield ['__isset', 1]; + yield ['__unset', 1]; + yield ['__sleep']; + yield ['__wakeup']; + yield ['__serialize']; + yield ['__unserialize', 1]; + yield ['__toString']; + yield ['__invoke']; + yield ['__set_state', 1, true]; + yield ['__clone']; + yield ['__debugInfo']; } } diff --git a/tests/Fixer/Import/OrderedImportsFixerTest.php b/tests/Fixer/Import/OrderedImportsFixerTest.php index ae5bf2bcaa6..b44ef40362b 100644 --- a/tests/Fixer/Import/OrderedImportsFixerTest.php +++ b/tests/Fixer/Import/OrderedImportsFixerTest.php @@ -557,7 +557,6 @@ public function testCodeWithCommentsAndMultiLine(): void public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/LanguageConstruct/DirConstantFixerTest.php b/tests/Fixer/LanguageConstruct/DirConstantFixerTest.php index baa5950b9db..a0e9133fe8a 100644 --- a/tests/Fixer/LanguageConstruct/DirConstantFixerTest.php +++ b/tests/Fixer/LanguageConstruct/DirConstantFixerTest.php @@ -143,21 +143,6 @@ public function &dirname($a); $x = dirname(dirname("a".__FILE__."a")); ', ], - ]; - } - - /** - * @requires PHP 7.3 - * @dataProvider provideFix73Cases - */ - public function testFix73(string $expected, string $input): void - { - $this->doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ [ 'fixer->configure($config); - $this->doTest($expected, $input); } @@ -114,6 +113,10 @@ public function provideFixCases(): \Generator '', [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES_EXCLUDE => ['trigger_error']], ], + [ + 'doTest( - 'fixer->configure($config); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php index 5422ffa8eb2..83f2881e032 100644 --- a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php +++ b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php @@ -207,21 +207,6 @@ public function provideFixCases(): array 'doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ [ ' [ + 'It replaces an unset on a property with = null' => [ 'bar = null;', 'bar);', ], - 'It replaces an unset on a property with = null II' => [ + 'It replaces an unset on a property with = null II' => [ 'bar = null ;', 'bar );', ], - 'It replaces an unset on a static property with = null' => [ + 'It replaces an unset on a static property with = null' => [ ' [ + 'It does not replace unset on a variable with = null' => [ 'a; unset($foo);', ], 'It replaces multiple unsets on variables with = null' => [ @@ -122,75 +122,47 @@ public function provideFixCases(): \Generator unset(c($a)->a); ', ]; - } - /** - * @dataProvider provideFixPre80Cases - * @requires PHP <8.0 - */ - public function testFixPre80(string $expected, string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixPre80Cases(): \Generator - { - yield 'It does not break curly access expressions' => [ - 'doTest($expected, $input); - } - - public function provideFix73Cases(): \Generator - { yield from [ - 'It replaces an unset on a property with = null' => [ + 'It replaces an unset on a property with = null 1' => [ 'bar = null;', 'bar,);', ], - 'It replaces multiple unsets, but not those that arent properties' => [ + 'It replaces multiple unsets, but not those that arent properties 1' => [ 'bar = null; $bar->foo = null; unset($bar,);', 'bar, $bar->foo, $bar,);', ], - 'It replaces an unset on a static property with = null' => [ + 'It replaces an unset on a static property with = null 1' => [ ' [ + 'It does not replace unset on a variable with = null 1' => [ 'a; unset($foo,);', ], - 'It replaces multiple unsets on variables with = null' => [ + 'It replaces multiple unsets on variables with = null 1' => [ 'bar = null; $bar->foo = null; $bar->baz = null; $a->ba = null;', 'bar, $bar->foo, $bar->baz, $a->ba,);', ], - 'It replaces multiple unsets, but not those that arent properties in multiple places' => [ + 'It replaces multiple unsets, but not those that arent properties in multiple places 1' => [ 'foo = null; unset($bar,);', 'foo, $bar,);', ], - 'It replaces $this -> and self:: replacements' => [ + 'It replaces $this -> and self:: replacements 1' => [ 'bar = null; self::$foo = null; unset($bar,);', 'bar, self::$foo, $bar,);', ], - 'It does not replace unsets on arrays' => [ + 'It does not replace unsets on arrays 1' => [ 'foo[0],);', ], - 'It works in a more complex unset' => [ + 'It works in a more complex unset 1' => [ 'foo[0]); self::$foo = null; \Test\Baz::$fooBar = null; unset($bar->foo[0]); $this->foo = null; unset($a); unset($b,);', 'foo[0], self::$foo, \Test\Baz::$fooBar, $bar->foo[0], $this->foo, $a, $b,);', ], - 'It works with consecutive unsets' => [ + 'It works with consecutive unsets 1' => [ 'bar = null; unset($foo); unset($bar); unset($baz); $this->ab = null;', 'bar, $foo, $bar, $baz, $this->ab,);', ], - 'It works when around messy whitespace' => [ + 'It works when around messy whitespace 1' => [ 'b = null; $this->a = null; unset($b,); @@ -200,22 +172,22 @@ public function provideFix73Cases(): \Generator unset($this->a, $b,); ', ], - 'It works with weirdly placed comments' => [ + 'It works with weirdly placed comments 11' => [ 'foo[0]); self::$foo = null/*baz*/; /*hello*/\Test\Baz::$fooBar = null/*comment*/; unset($bar->foo[0]); $this->foo = null; unset($a); unset($b,); unset/*foo*/(/*bar*/$bar,);', 'foo[0], self::$foo/*baz*/, /*hello*/\Test\Baz::$fooBar/*comment*/, $bar->foo[0], $this->foo, $a, $b,); unset/*foo*/(/*bar*/$bar,);', ], - 'It does not mess with consecutive unsets' => [ + 'It does not mess with consecutive unsets 1' => [ 'a = null;', 'a,);', ], - 'It does not replace function call with class constant inside' => [ + 'It does not replace function call with class constant inside 1' => [ ' [ + 'It does not replace function call with class constant and property inside 1' => [ 'property[array_search(\Types::TYPE_RANDOM, $this->property)],);', ], [ @@ -233,9 +205,25 @@ public function provideFix73Cases(): \Generator ]; if (\PHP_VERSION_ID < 80000) { - yield 'It does not replace unsets on arrays with special notation' => [ + yield 'It does not replace unsets on arrays with special notation 1' => [ 'foo{0},);', ]; } } + + /** + * @dataProvider provideFixPre80Cases + * @requires PHP <8.0 + */ + public function testFixPre80(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield 'It does not break curly access expressions' => [ + 'fixer->configure([ - 'constructs' => [ - 'private', - ], - ]); - - $this->doTest($expected, $input); - } - - public function provideFixWithPrivatePhp71Cases(): array - { - return [ [ 'fixer->configure([ - 'constructs' => [ - 'protected', - ], - ]); - - $this->doTest($expected, $input); - } - - public function provideFixWithProtectedPhp71Cases(): array - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ [ '$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h;', '$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h += 1;', ]; - } - /** - * @dataProvider provideFix74Cases - * @requires PHP 7.4 - */ - public function testFix74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ - [ - 'fixer->configure($config); + if (null !== $config) { + $this->fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -343,6 +346,54 @@ public function testBar() }', ['target' => PhpUnitTargetVersion::VERSION_NEWEST], ], + [ + 'expectException("RuntimeException"); + $this->expectExceptionMessage("msg"/*B*/); + $this->expectExceptionCode(/*C*/123); + zzz(); + } + }', + 'setExpectedException("RuntimeException", "msg"/*B*/, /*C*/123, ); + zzz(); + } + }', + ], + [ + 'expectException("RuntimeException"); + $this->expectExceptionMessage("msg"/*B*/); + $this->expectExceptionCode(/*C*/123/*D*/); + zzz(); + } + }', + 'setExpectedException("RuntimeException", "msg"/*B*/, /*C*/123, /*D*/); + zzz(); + } + }', + ], ]; } @@ -400,69 +451,6 @@ final class MyTest extends \PHPUnit_Framework_TestCase return [[$expected, $input]]; } - /** - * @requires PHP 7.3 - * @dataProvider provideFix73Cases - */ - public function testFix73(string $expected, string $input): void - { - $this->doTest($expected, $input); - } - - public function provideFix73Cases(): array - { - return [ - [ - 'expectException("RuntimeException"); - $this->expectExceptionMessage("msg"/*B*/); - $this->expectExceptionCode(/*C*/123); - zzz(); - } - }', - 'setExpectedException("RuntimeException", "msg"/*B*/, /*C*/123, ); - zzz(); - } - }', - ], - [ - 'expectException("RuntimeException"); - $this->expectExceptionMessage("msg"/*B*/); - $this->expectExceptionCode(/*C*/123/*D*/); - zzz(); - } - }', - 'setExpectedException("RuntimeException", "msg"/*B*/, /*C*/123, /*D*/); - zzz(); - } - }', - ], - ]; - } - /** * @requires PHP 8.0 */ diff --git a/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php index 47557d42753..71cd6e4aefa 100644 --- a/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php @@ -31,7 +31,10 @@ final class PhpUnitMockFixerTest extends AbstractFixerTestCase */ public function testFix(string $expected, ?string $input = null, array $config = []): void { - $this->fixer->configure($config); + if (null !== $config) { + $this->fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -103,16 +106,8 @@ public function testFoo() } }', ], - ]; - } - - /** - * @requires PHP 7.3 - */ - public function testFix73(): void - { - $this->doTest( - 'getMock("Foo", ["bbb", ], ["argument", ], ); } }', - 'getMock("Foo", ["aaa"], ["argument"], ); $this->getMock("Foo", ["bbb", ], ["argument", ], ); } - }' - ); + }', + ], + ]; } /** diff --git a/tests/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixerTest.php index 1126c34b93a..ad8749e73e3 100644 --- a/tests/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixerTest.php @@ -249,28 +249,21 @@ public function testFoo() { } }', ], - ]; - } - - /** - * @requires PHP 7.3 - */ - public function testFix73(): void - { - $this->doTest( - 'method("someMethod")->willReturn( 10 , ); } }', - 'method("someMethod")->will($this->returnValue( 10 , )); } -}' - ); +}', + ], + ]; } /** diff --git a/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php index 21b88a7e75e..0e0f14538d0 100644 --- a/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php @@ -37,60 +37,71 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases(): array + public function provideTestFixCases(): iterable { - $cases = [ - ['foo();'], - [self::generateTest('$self->foo();')], - ]; + yield ['foo();']; + + yield [self::generateTest('$self->foo();')]; foreach ($this->getMethodsMap() as $methodBefore => $methodAfter) { - $cases[] = [self::generateTest("\$sth->{$methodBefore}(1, 1);")]; - $cases[] = [self::generateTest("\$sth->{$methodAfter}(1, 1);")]; - $cases[] = [self::generateTest("\$this->{$methodBefore}(1, 2, 'message', \$toMuch);")]; + yield [self::generateTest("\$sth->{$methodBefore}(1, 1);")]; + + yield [self::generateTest("\$sth->{$methodAfter}(1, 1);")]; - $cases[] = [ + yield [self::generateTest("\$this->{$methodBefore}(1, 2, 'message', \$toMuch);")]; + + yield [ self::generateTest("\$this->{$methodAfter}(1, 2);"), self::generateTest("\$this->{$methodBefore}(1, 2);"), ]; - $cases[] = [ + yield [ self::generateTest("\$this->{$methodAfter}(1, 2); \$this->{$methodAfter}(1, 2);"), self::generateTest("\$this->{$methodBefore}(1, 2); \$this->{$methodBefore}(1, 2);"), ]; - $cases[] = [ + yield [ self::generateTest("\$this->{$methodAfter}(1, 2, 'description');"), self::generateTest("\$this->{$methodBefore}(1, 2, 'description');"), ]; - $cases[] = [ + yield [ self::generateTest("\$this->/*aaa*/{$methodAfter} \t /**bbb*/ ( /*ccc*/1 , 2);"), self::generateTest("\$this->/*aaa*/{$methodBefore} \t /**bbb*/ ( /*ccc*/1 , 2);"), ]; - $cases[] = [ + yield [ self::generateTest("\$this->{$methodAfter}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');"), self::generateTest("\$this->{$methodBefore}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');"), ]; - $cases[] = [ + yield [ self::generateTest("self::{$methodAfter}(1, 2);"), self::generateTest("self::{$methodBefore}(1, 2);"), ]; - $cases[] = [ + yield [ self::generateTest("static::{$methodAfter}(1, 2);"), self::generateTest("static::{$methodBefore}(1, 2);"), ]; - $cases[] = [ + yield [ self::generateTest("STATIC::{$methodAfter}(1, 2);"), self::generateTest("STATIC::{$methodBefore}(1, 2);"), ]; } - return $cases; + foreach ($this->getMethodsMap() as $methodBefore => $methodAfter) { + yield [ + self::generateTest("static::{$methodAfter}(1, 2,);"), + self::generateTest("static::{$methodBefore}(1, 2,);"), + ]; + + yield [ + self::generateTest("self::{$methodAfter}(1, \$a, '', );"), + self::generateTest("self::{$methodBefore}(1, \$a, '', );"), + ]; + } } /** @@ -137,30 +148,6 @@ public function testInvalidConfig(): void $this->fixer->configure(['assertions' => ['__TEST__']]); } - /** - * @requires PHP 7.3 - * @dataProvider provideFix73Cases - */ - public function testFix73(string $expected, string $input): void - { - $this->doTest($expected, $input); - } - - public function provideFix73Cases(): \Generator - { - foreach ($this->getMethodsMap() as $methodBefore => $methodAfter) { - yield [ - self::generateTest("static::{$methodAfter}(1, 2,);"), - self::generateTest("static::{$methodBefore}(1, 2,);"), - ]; - - yield [ - self::generateTest("self::{$methodAfter}(1, \$a, '', );"), - self::generateTest("self::{$methodBefore}(1, \$a, '', );"), - ]; - } - } - /** * @return array */ diff --git a/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php index d547ed9236e..a47916c2573 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php @@ -984,7 +984,6 @@ public function testMessyWhitespaces(string $expected, ?string $input = null, ar { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure($config); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php b/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php index 4756a6737e0..706e05c694f 100644 --- a/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php +++ b/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php @@ -1594,22 +1594,6 @@ function f3(string &...$x) {} function f(string &...$x) {} }', ], - ]; - } - - /** - * @dataProvider provideFixPhp74Cases - * @requires PHP 7.4 - */ - public function testFixPhp74(string $expected, ?string $input = null, array $config = []): void - { - $this->fixer->configure($config); - $this->doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ 'some typed static public property' => [ 'fixer->configure($config ?? ['only_untyped' => false]); - $this->doTest($expected, $input); } @@ -375,7 +374,6 @@ public function testMessyWhitespaces(string $expected, ?string $input = null, ?a { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure($config ?? ['only_untyped' => false]); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php index 4a5041633a0..03730c1ee83 100644 --- a/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php @@ -1129,7 +1129,6 @@ public function testDoesNotAlignWithEmptyConfig(): void public function testVariadicParams(array $config, string $expected, string $input): void { $this->fixer->configure($config); - $this->doTest($expected, $input); } @@ -1251,7 +1250,6 @@ class Foo {} public function testInvalidPhpdocsAreUnchanged(array $config, string $input): void { $this->fixer->configure($config); - $this->doTest($input); } diff --git a/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php b/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php index 46b605b9ca8..defe0b904ad 100644 --- a/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php @@ -512,22 +512,6 @@ class Foo 'property' => 'single', ], ], - ]; - } - - /** - * @requires PHP 7.4 - * @dataProvider provideFixPhp74Cases - */ - public function testFixPhp74(string $expected, string $input = null, array $config = []): void - { - $this->fixer->configure($config); - $this->doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ 'It can handle properties with type declaration' => [ 'fixer->configure($config); + if (null !== $config) { + $this->fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -739,21 +742,6 @@ public function provideFixCases(): array [$a] = $b; ', ], - ]; - } - - /** - * @dataProvider provideFix74Cases - * @requires PHP 7.4 - */ - public function testFix74(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ [ 'fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure(['strategy' => MultilineWhitespaceBeforeSemicolonsFixer::STRATEGY_NO_MULTI_LINE]); - $this->doTest($expected, $input); } @@ -848,7 +847,6 @@ public function testMessyWhitespacesSemicolonForChainedCalls(string $expected, ? { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure(['strategy' => MultilineWhitespaceBeforeSemicolonsFixer::STRATEGY_NEW_LINE_FOR_CHAINED_CALLS]); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/Strict/StrictParamFixerTest.php b/tests/Fixer/Strict/StrictParamFixerTest.php index 80b6c485a10..bf105e33262 100644 --- a/tests/Fixer/Strict/StrictParamFixerTest.php +++ b/tests/Fixer/Strict/StrictParamFixerTest.php @@ -176,28 +176,14 @@ public function __construct($foo, $bar) {} 'doTest($expected, $input); - } - - public function provideFix73Cases(): \Generator - { - yield [ - 'fixer->configure($configuration); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php b/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php index 6cf5d890ae8..7b579d4ddac 100644 --- a/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php +++ b/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php @@ -120,15 +120,8 @@ public function provideFixCases(): array EOD; ', ], - ]; - } - - /** - * @requires PHP 7.3 - */ - public function testFix73(): void - { - $expected = ' + [ + ' doTest($expected, $input); +', + ], + ]; } } diff --git a/tests/Fixer/StringNotation/StringLengthToEmptyFixerTest.php b/tests/Fixer/StringNotation/StringLengthToEmptyFixerTest.php index 592dfa3daee..7fdfb2b1c16 100644 --- a/tests/Fixer/StringNotation/StringLengthToEmptyFixerTest.php +++ b/tests/Fixer/StringNotation/StringLengthToEmptyFixerTest.php @@ -273,18 +273,11 @@ public function provideTestFixCases(): \Generator 'doTest( + yield [ 'doTest($expected, $input); - } - - public function provideFixPhp74Cases(): array - { - return [ - [ - <<<'EXPECTED' -fixer->configure(['statements' => $statements]); - $this->doTest($expected, $input); } diff --git a/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php b/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php index ed1f6b3413a..cbfd421e1f9 100644 --- a/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php +++ b/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php @@ -26,14 +26,14 @@ final class CompactNullableTypehintFixerTest extends AbstractFixerTestCase { /** - * @dataProvider provideFix71Cases + * @dataProvider provideFixCases */ - public function testFix71(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } - public function provideFix71Cases(): array + public function provideFixCases(): array { return [ [ @@ -106,21 +106,6 @@ public function provideFix71Cases(): array 'doTest($expected, $input); - } - - public function provideFix74Cases(): array - { - return [ [ 'fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t")); diff --git a/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php b/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php index 8440ccce472..0924b824076 100644 --- a/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php +++ b/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php @@ -233,6 +233,23 @@ public function provideFixCases(): array 2 => 2, )) ->setY(); +', + ], + [ + 'setEmail("voff.web@gmail.com", ) + ->setPassword("233434" ,) + ->setEmailConfirmed(false , ) + ->setEmailConfirmationCode("123456", ); +', + 'setEmail("voff.web@gmail.com", ) + + ->setPassword("233434" ,) + ->setEmailConfirmed(false , ) +->setEmailConfirmationCode("123456", ); ', ], ]; @@ -257,30 +274,6 @@ public function provideWindowsWhitespacesCases(): array ]; } - /** - * @requires PHP 7.3 - */ - public function testFix73(): void - { - $this->doTest( - 'setEmail("voff.web@gmail.com", ) - ->setPassword("233434" ,) - ->setEmailConfirmed(false , ) - ->setEmailConfirmationCode("123456", ); -', - 'setEmail("voff.web@gmail.com", ) - - ->setPassword("233434" ,) - ->setEmailConfirmed(false , ) -->setEmailConfirmationCode("123456", ); -' - ); - } - /** * @requires PHP 8.0 */ diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 1cb1d4141a2..842be5d8593 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -103,7 +103,6 @@ private function test123(){ public function testWithConfig(array $lineNumberRemoved, array $config): void { $this->fixer->configure(['tokens' => $config]); - $this->doTest($this->removeLinesFromString($this->template, $lineNumberRemoved), $this->template); } @@ -665,7 +664,6 @@ public function testRemoveBetweenUseTraits(string $expected, string $input): voi { $this->expectDeprecation('Option "tokens: use_trait" used in `no_extra_blank_lines` rule is deprecated, use the rule `class_attributes_separation` with `elements: trait_import` instead.'); $this->fixer->configure(['tokens' => ['use_trait']]); - $this->doTest($expected, $input); } @@ -917,7 +915,6 @@ public function testMessyWhitespaces(array $config, string $expected, ?string $i { $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n")); $this->fixer->configure($config); - $this->doTest($expected, $input); } @@ -1092,7 +1089,6 @@ class Foo {}' public function testFix80(string $expected): void { $this->fixer->configure(['tokens' => ['throw']]); - $this->doTest($expected); } diff --git a/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php b/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php index 68458634254..393190ab8ca 100644 --- a/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php +++ b/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php @@ -355,46 +355,31 @@ public function provideConfigurationCases(): \Generator yield $index => $test; } - } - - public function testWrongConfig(): void - { - $this->expectException(InvalidFixerConfigurationException::class); - $this->expectExceptionMessageMatches('/^\[no_spaces_around_offset\] Invalid configuration: The option "positions" .*\.$/'); - - $this->fixer->configure(['positions' => ['foo']]); - } - - /** - * @dataProvider providePHP71Cases - * @requires PHP 7.1 - */ - public function testPHP71(array $configuration, string $expected, string $input): void - { - $this->fixer->configure($configuration); - $this->doTest($expected, $input); - } - public function providePHP71Cases(): array - { - return [ - 'Config "default".' => [ - ['positions' => ['inside', 'outside']], - ' [ + ['inside', 'outside'], + 'attributes->get(1)) { return false; } [ $class , $method ] = $this->splitControllerClassAndMethod($controllerName); $a = $b[0]; ', - 'attributes->get(1)) { return false; } [ $class , $method ] = $this->splitControllerClassAndMethod($controllerName); $a = $b [0]; ', - ], ]; } + + public function testWrongConfig(): void + { + $this->expectException(InvalidFixerConfigurationException::class); + $this->expectExceptionMessageMatches('/^\[no_spaces_around_offset\] Invalid configuration: The option "positions" .*\.$/'); + + $this->fixer->configure(['positions' => ['foo']]); + } } diff --git a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php index 78f76b10c58..8988a86a596 100644 --- a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php +++ b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php @@ -73,6 +73,7 @@ public function provideFix80Cases(): \Generator 'check(); } - /** - * @requires PHP 7.3 - */ public function testTokenizerLintingResultFailCompileError(): void { $error = new \CompileError('Multiple access type modifiers are not allowed'); diff --git a/tests/Test/TestCaseUtils.php b/tests/Test/TestCaseUtils.php index ad6390d9eb3..c95222bc312 100644 --- a/tests/Test/TestCaseUtils.php +++ b/tests/Test/TestCaseUtils.php @@ -29,6 +29,7 @@ public static function swapExpectedInputTestCases(iterable $cases): iterable } [$case[0], $case[1]] = [$case[1], $case[0]]; + yield $case; } } diff --git a/tests/TextDiffTest.php b/tests/TextDiffTest.php index 93b99816843..a8c616f84dd 100644 --- a/tests/TextDiffTest.php +++ b/tests/TextDiffTest.php @@ -73,12 +73,14 @@ public function provideDiffReportingCases(): \Generator foreach (['txt', 'xml', 'junit'] as $format) { yield [$expected, $format, true]; + yield [$expected, $format, false]; } $expected = substr(json_encode($expected), 1, -1); yield [$expected, 'json', true]; + yield [$expected, 'json', false]; } diff --git a/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php index c3600e07a64..c1faad947ff 100644 --- a/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php @@ -71,28 +71,17 @@ public function provideArgumentsCases(): \Generator yield [' 11]]; yield [' 12, 14 => 20]]; - } - - /** - * @requires PHP 7.3 - * @dataProvider provideArguments73Cases - */ - public function testArguments73(string $code, int $openIndex, int $closeIndex, array $arguments): void - { - $tokens = Tokens::fromCode($code); - $analyzer = new ArgumentsAnalyzer(); - - static::assertSame(\count($arguments), $analyzer->countArguments($tokens, $openIndex, $closeIndex)); - static::assertSame($arguments, $analyzer->getArguments($tokens, $openIndex, $closeIndex)); - } - public function provideArguments73Cases(): iterable - { yield [' 3]]; + yield [' 3]]; + yield [' 14]]; + yield [' 15]]; + yield [' 5, 7 => 7, 9 => 9, 11 => 11, 13 => 13]]; + yield [' 3, 5 => 7]]; } @@ -112,9 +101,13 @@ public function testArguments80(string $code, int $openIndex, int $closeIndex, a public function provideArguments80Cases(): \Generator { yield [' 22]]; + yield [' 22]]; + yield [' 22]]; + yield [' 13, 15 => 22]]; + yield [' 9, 11 => 15]]; } diff --git a/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php b/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php index 362ea5684de..b28ac1522c2 100644 --- a/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php @@ -65,36 +65,67 @@ public function testIsAttribute(bool $isInAttribute, string $code): void public static function provideIsAttributeCases(): iterable { yield [false, 'isBlock($tokens, $openIndex, $closeIndex)); + static::assertSame($isBlock, $analyzer->isBlock($tokens, $openIndex, $closeIndex)); } public function provideNonBlocksCases(): array @@ -82,25 +79,7 @@ public function provideNonBlocksCases(): array ['isBlock($tokens, $openIndex, $closeIndex)); - } - - public function provideBlocksPhp74Cases(): array - { - return [ - [' $x + 10;', 6, 8], + [' $x + 10;', 6, 8, true], ]; } } diff --git a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php index e22a18470c8..9a876c8dbeb 100644 --- a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php @@ -307,7 +307,6 @@ public function testNotPhpdocCandidate71(): void /** * @dataProvider providePhpdocCandidatePhp74Cases - * @requires PHP 7.4 */ public function testPhpdocCandidatePhp74(string $code): void { diff --git a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php index 637f9137f86..d362c1d5501 100644 --- a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php @@ -244,16 +244,6 @@ function A(){} [1, 6, 11, 16, 21, 26], ]; - if (\PHP_VERSION_ID < 80000) { - yield [ - ' false;', [], ]; + + if (\PHP_VERSION_ID < 80000) { + yield [ + ' new ArgumentAnalysis( - '$a', - 9, - null, - new TypeAnalysis( - '\Foo\Bar', - 3, - 7 - ) - ), - ]]; - } - } - - public function provideFunctionReturnTypeInfoCases(): \Generator - { - yield ['getFunctionArguments($tokens, $methodIndex))); - } - - public function provideFunctionsWithArgumentsPhp74Cases(): \Generator - { yield from [ [' null;', 1, []], [' null;', 1, [ @@ -612,6 +556,34 @@ public function provideFunctionsWithArgumentsPhp74Cases(): \Generator ) ), ]]; + + yield [' new ArgumentAnalysis( + '$a', + 9, + null, + new TypeAnalysis( + '\Foo\Bar', + 3, + 7 + ) + ), + ]]; + } + } + + public function provideFunctionReturnTypeInfoCases(): \Generator + { + yield [' null;', 1, null]; + yield [' null;', 1, null]; + yield [' null;', 1, new TypeAnalysis('array', 7, 7)]; + yield [' null;', 1, new TypeAnalysis('\Foo\Bar', 7, 10)]; + yield [' null;', 1, new TypeAnalysis('array', 8, 8)]; if (\PHP_VERSION_ID < 80000) { diff --git a/tests/Tokenizer/Analyzer/ReferenceAnalyzerTest.php b/tests/Tokenizer/Analyzer/ReferenceAnalyzerTest.php index c16a45aabac..4135407f707 100644 --- a/tests/Tokenizer/Analyzer/ReferenceAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/ReferenceAnalyzerTest.php @@ -55,11 +55,17 @@ public function testReference(string $code): void public static function provideReferenceCases(): \Generator { yield ['value; } }']; + yield [' &$foo) {}']; + yield ['baz & $qux);']; + yield ['getForeachToken(), $this->getBraceToken()] as $token) { yield [$token->getId(), $token->getContent(), false]; + yield [$token->getId(), strtolower($token->getContent()), false]; } } @@ -318,28 +319,47 @@ public function provideEqualsCases(): \Generator $function = new Token([T_FUNCTION, 'function', 1]); yield [$brace, false, '!']; + yield [$brace, false, '!', false]; + yield [$brace, true, '(']; + yield [$brace, true, '(', false]; + yield [$function, false, '(']; + yield [$function, false, '(', false]; yield [$function, false, [T_NAMESPACE]]; + yield [$function, false, [T_NAMESPACE], false]; + yield [$function, false, [T_VARIABLE, 'function']]; + yield [$function, false, [T_VARIABLE, 'function'], false]; + yield [$function, false, [T_VARIABLE, 'Function']]; + yield [$function, false, [T_VARIABLE, 'Function'], false]; + yield [$function, true, [T_FUNCTION]]; + yield [$function, true, [T_FUNCTION], false]; + yield [$function, true, [T_FUNCTION, 'function']]; + yield [$function, true, [T_FUNCTION, 'function'], false]; + yield [$function, false, [T_FUNCTION, 'Function']]; + yield [$function, true, [T_FUNCTION, 'Function'], false]; + yield [$function, false, [T_FUNCTION, 'junction'], false]; yield [$function, true, new Token([T_FUNCTION, 'function'])]; + yield [$function, false, new Token([T_FUNCTION, 'Function'])]; + yield [$function, true, new Token([T_FUNCTION, 'Function']), false]; // if it is an array any additional field is checked too @@ -348,10 +368,15 @@ public function provideEqualsCases(): \Generator yield [new Token('&'), true, '&']; if (\defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG')) { // @TODO: drop condition with new MAJOR release 4.0 yield [new Token('&'), true, new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&'])]; + yield [new Token('&'), true, new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&'])]; + yield [new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, '&']; + yield [new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&'])]; + yield [new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, '&']; + yield [new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&'])]; } } @@ -380,12 +405,19 @@ public function provideEqualsAnyCases(): \Generator $foreach = $this->getForeachToken(); yield [false, []]; + yield [false, [$brace]]; + yield [false, [$brace, $foreach]]; + yield [true, [$brace, $foreach, [T_FUNCTION]]]; + yield [true, [$brace, $foreach, [T_FUNCTION, 'function']]]; + yield [false, [$brace, $foreach, [T_FUNCTION, 'Function']]]; + yield [true, [$brace, $foreach, [T_FUNCTION, 'Function']], false]; + yield [false, [[T_VARIABLE, 'junction'], [T_FUNCTION, 'junction']], false]; } @@ -402,16 +434,27 @@ public function testIsKeyCaseSensitive(bool $isKeyCaseSensitive, $caseSensitive, public function provideIsKeyCaseSensitiveCases(): \Generator { yield [true, true, 0]; + yield [true, true, 1]; + yield [true, [], 0]; + yield [true, [true], 0]; + yield [true, [false, true], 1]; + yield [true, [false, true, false], 1]; + yield [true, [false], 10]; + yield [false, false, 10]; + yield [false, [false], 0]; + yield [false, [true, false], 1]; + yield [false, [true, false, true], 1]; + yield [false, [1 => false], 1]; } diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 675613c0341..75a328ad985 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -191,9 +191,6 @@ class Foo2 ]; } - /** - * @requires PHP 7.4 - */ public function testGetClassyElementsWithNullableProperties(): void { $source = <<<'PHP' @@ -1604,7 +1601,6 @@ public function provideIsArray71Cases(): array /** * @dataProvider provideIsBinaryOperator71Cases - * @requires PHP 7.1 */ public function testIsBinaryOperator71(array $expected, string $source): void { @@ -1626,28 +1622,7 @@ public function provideIsBinaryOperator71Cases(): \Generator [11 => false], ' $isBinary) { - static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); - - if ($isBinary) { - static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); - static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); - } - } - } - - public function provideIsBinaryOperator74Cases(): \Generator - { yield [ [3 => true], '"]; + yield [false, "#!\n "]; + yield [false, "']; + yield [false, ' World!']; // short open tag yield [(bool) \ini_get('short_open_tag'), ""]; + yield [false, " "]; + yield [false, ""]; + yield [false, " "]; + yield [false, ">' => [4, 3, 1, ' [null, 6, 1, ' [null, 888, 1, ' CT::T_ARRAY_TYPEHINT, ], ], - ]; - } - - /** - * @dataProvider provideProcessPhp74Cases - * @requires PHP 7.4 - */ - public function testProcessPhp74(string $source, array $expectedTokens = []): void - { - $this->doTest( - $source, - $expectedTokens, - [ - T_ARRAY, - CT::T_ARRAY_TYPEHINT, - ] - ); - } - - public function provideProcessPhp74Cases(): array - { - return [ [ ' $expectedTokens - * @param string[] $observedKinds - * - * @dataProvider provideProcessPhp70Cases - */ - public function testProcessPhp70(string $source, array $expectedTokens, array $observedKinds = []): void - { - $this->doTest( - $source, - $expectedTokens, - $observedKinds - ); - } - - public function provideProcessPhp70Cases(): array - { - return [ [ ' $expectedTokens - * @param string[] $observedKinds - * - * @dataProvider provideProcessPhp74Cases - * @requires PHP 7.4 - */ - public function testProcessPhp74(string $source, array $expectedTokens, array $observedKinds = []): void - { - $this->doTest( - $source, - $expectedTokens, - $observedKinds - ); - } - - public function provideProcessPhp74Cases(): array - { - return [ [ ' null;', [ diff --git a/tests/Tokenizer/Transformer/NullableTypeTransformerTest.php b/tests/Tokenizer/Transformer/NullableTypeTransformerTest.php index 8f8bdbeb8b0..a9ffeda9e12 100644 --- a/tests/Tokenizer/Transformer/NullableTypeTransformerTest.php +++ b/tests/Tokenizer/Transformer/NullableTypeTransformerTest.php @@ -64,27 +64,6 @@ public function provideProcessCases(): array $c = 1 ?: []; ', ], - ]; - } - - /** - * @dataProvider provideProcess74Cases - * @requires PHP 7.4 - */ - public function testProcess74(string $source, array $expectedTokens = []): void - { - $this->doTest( - $source, - $expectedTokens, - [ - CT::T_NULLABLE_TYPE, - ] - ); - } - - public function provideProcess74Cases(): array - { - return [ [ 'doTest( - $source, - $expectedTokens, - [ - CT::T_RETURN_REF, - ] - ); - } - - public function provideProcessPhp74Cases(): array - { - return [ [ ' [];', [ diff --git a/tests/Tokenizer/Transformer/TypeColonTransformerTest.php b/tests/Tokenizer/Transformer/TypeColonTransformerTest.php index a2bde32caf0..9d0a0923bba 100644 --- a/tests/Tokenizer/Transformer/TypeColonTransformerTest.php +++ b/tests/Tokenizer/Transformer/TypeColonTransformerTest.php @@ -80,27 +80,6 @@ public function provideProcessCases(): array $c = 1 ?: []; ', ], - ]; - } - - /** - * @dataProvider provideProcessPhp74Cases - * @requires PHP 7.4 - */ - public function testProcessPhp74(string $source, array $expectedTokens = []): void - { - $this->doTest( - $source, - $expectedTokens, - [ - CT::T_TYPE_COLON, - ] - ); - } - - public function provideProcessPhp74Cases(): array - { - return [ [ ' [];', [