* Dariusz RumiƄski * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Fixer\FunctionNotation; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Jan Gantzert * * @internal * * @group phpdoc * * @covers \PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer */ final class PhpdocToParamTypeFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $config * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield 'type declaration already defined' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' $foo */ function my_foo(array $foo) {}', ' $foo */ function my_foo($foo) {}', ]; yield 'generics with multiple types' => [ ' $foo */ function my_foo(array $foo) {}', ' $foo */ function my_foo($foo) {}', ]; yield 'stop searching last token' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' false], ]; yield 'do not fix union types when configured as such' => [ ' false], ]; yield 'do not fix function call' => [ ' [ ' [ ' [ ' [ ' [ ' [$a], fn($a, $b) => 1, );', ' [$a], fn($a, $b) => 1, );', ]; } /** * @dataProvider provideFixPre80Cases * * @requires PHP <8.0 */ public function testFixPre80(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixPre80Cases(): iterable { yield 'skip mixed type of param' => [ ' [ ' [ ' [ ' [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield 'non-root class with mixed type of param for php >= 8' => [ ' [ ' [ ' [ '|string $bar */ function my_foo(array|string $bar) {}', '|string $bar */ function my_foo($bar) {}', ]; yield 'fix union types including generics' => [ ' $bar */ function my_foo(string|array $bar) {}', ' $bar */ function my_foo($bar) {}', ]; yield 'union types including array' => [ ' [ '