* 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 Mark Nielsen * * @internal * * @covers \PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer> */ final class VoidReturnFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixCases(): iterable { yield [' null;', ]; yield [ ' 1;', ]; yield [ ' var_dump($a);', ]; $excluded = ['__clone', '__construct', '__debugInfo', '__destruct', '__isset', '__serialize', '__set_state', '__sleep', '__toString']; foreach (self::provideMagicMethodsDefinitions() as $magicMethodsDefinition) { $name = $magicMethodsDefinition[0]; $arguments = $magicMethodsDefinition[1] ?? 0; $isStatic = $magicMethodsDefinition[2] ?? false; $code = \sprintf( ' \sprintf('$x%d', $n), array_keys(array_fill(0, $arguments, true)), )) ); $input = \sprintf($code, ''); $expected = \sprintf($code, \in_array($name, $excluded, true) ? '' : ': void'); yield \sprintf('Test if magic method %s is handled without causing syntax error', $name) => [ $expected, $expected === $input ? null : $input, ]; } } /** * @dataProvider provideFix80Cases * * @requires PHP 8.0 */ public function testFix80(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ ' */ private static function provideMagicMethodsDefinitions(): 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']; } }