* 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\Phpdoc; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Graham Campbell * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer> */ final class PhpdocVarWithoutNameFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixVarCases */ public function testFixVar(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @dataProvider provideFixVarCases */ public function testFixType(string $expected, ?string $input = null): void { $expected = str_replace('@var', '@type', $expected); if (null !== $input) { $input = str_replace('@var', '@type', $input); } $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixVarCases(): iterable { yield 'testFixVar' => [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' doSomething(1); /** * @var $bar \Foo\Bar */ $bar->doSomething(2); /** * @var User $bar */ ($bar = tmp())->doSomething(3); /** * @var User $bar */ list($bar) = a(); ', ]; yield 'const are not handled by this fixer' => [ ' SKIPPED_TYPES */ private const SKIPPED_TYPES = ["a" => true]; } ', ]; yield 'trait' => [ ' [ <<<'EOF' |false Hello! */ public $foo; /** @var int Hello! */ public $foo2; /** @var int Hello! */ public $foo3; /** @var int Hello! */ public $foo4; } EOF, <<<'EOF' |false $foo Hello! */ public $foo; /** @var int $thi Hello! */ public $foo2; /** @var int $thiss Hello! */ public $foo3; /** @var int $this2 Hello! */ public $foo4; } EOF, ]; yield 'testFixMultibyteVariableName' => [ <<<'EOF' [ <<<'EOF' */ protected $bar; } EOF, <<<'EOF' */ protected $bar; } EOF, ]; } /** * @dataProvider provideFix81Cases * * @requires PHP 8.1 */ public function testFix81(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield 'readonly' => [ ' [ ' SKIPPED_TYPES */ final public const SKIPPED_TYPES = ["a" => true]; } ', ]; } }