* 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 Ceeram * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer */ final class PhpdocToCommentFixerTest 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 [ 'open($path); }', ]; yield [ ' $sqlite) { $sqlite->open($path); }', ]; yield [ ' $sqlite) { $sqlite->open($path); }', ]; yield [ ' $sqlite) { $sqlite->open($path); }', ' $sqlite) { $sqlite->open($path); }', ]; yield [ 'open($path); ', 'open($path); ', ]; yield [ 'getPairs($c->bar(), $bar) as $index => list($a, $b)) { // Do something with $index, $a and $b } /** @var \Closure $value */ if (!$value = $this->getValue()) { return false; } /** @var string $name */ switch ($name = $this->getName()) { case "John": return false; case "Jane": return true; } /** @var string $content */ while ($content = $this->getContent()) { $name .= $content; } /** @var int $size */ for($i = 0, $size = count($people); $i < $size; ++$i) { $people[$i][\'salt\'] = mt_rand(000000, 999999); }', ]; yield [ 'getPairs($c->bar(), $bar) as $index => list($a, $b)) { // Do something with $index, $a and $b } /* @var \Closure $notValue */ if (!$value = $this->getValue()) { return false; } /* @var string $notName */ switch ($name = $this->getName()) { case "John": return false; case "Jane": return true; } /* @var string $notContent */ while ($content = $this->getContent()) { $name .= $content; } /* @var int $notSize */ for($i = 0, $size = count($people); $i < $size; ++$i) { $people[$i][\'salt\'] = mt_rand(000000, 999999); }', 'getPairs($c->bar(), $bar) as $index => list($a, $b)) { // Do something with $index, $a and $b } /** @var \Closure $notValue */ if (!$value = $this->getValue()) { return false; } /** @var string $notName */ switch ($name = $this->getName()) { case "John": return false; case "Jane": return true; } /** @var string $notContent */ while ($content = $this->getContent()) { $name .= $content; } /** @var int $notSize */ for($i = 0, $size = count($people); $i < $size; ++$i) { $people[$i][\'salt\'] = mt_rand(000000, 999999); }', ]; yield [ ' $sqlite) { $sqlite->open($path); }', null, ['ignored_tags' => ['todo']], ]; yield [ ' $sqlite) { $sqlite->open($path); } /** @todo Do not convert this */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ' $sqlite) { $sqlite->open($path); } /** @todo Do not convert this */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ['ignored_tags' => ['todo']], ]; yield [ ' $sqlite) { $sqlite->open($path); } /** @fix-me Do not convert this */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ' $sqlite) { $sqlite->open($path); } /** @fix-me Do not convert this */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ['ignored_tags' => ['fix-me']], ]; yield [ ' $sqlite) { $sqlite->open($path); } /** @TODO Do not convert this */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ' $sqlite) { $sqlite->open($path); } /** @TODO Do not convert this */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ['ignored_tags' => ['todo']], ]; yield [ ' $sqlite) { $sqlite->open($path); } /** * @deprecated This tag is not in the list but the next one is * @todo This should be a PHPDoc as the tag is on "ignored_tags" list */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ' $sqlite) { $sqlite->open($path); } /** * @deprecated This tag is not in the list but the next one is * @todo This should be a PHPDoc as the tag is on "ignored_tags" list */ foreach($connections as $key => $sqlite) { $sqlite->open($path); }', ['ignored_tags' => ['todo']], ]; yield 'do not convert before fn' => [ ' $x + 42; ', ]; yield 'convert before return without option' => [ ' false], ]; yield 'do not convert before return with option' => [ ' true], ]; yield [ 'doSomething(); /** @var Session $session */ # test $session = new Session(); ', ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'doTest($expected); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield 'enum' => [ ' [ '