* 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\Alias; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Vladimir Reznichenko * * @internal * * @covers \PhpCsFixer\AbstractFunctionReferenceFixer * @covers \PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer */ final class RandomApiMigrationFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideInvalidConfigurationCases */ public function testInvalidConfiguration(string $message, array $configuration): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage($message); $this->fixer->configure($configuration); } public static function provideInvalidConfigurationCases(): iterable { yield 'not supported function' => [ '[random_api_migration] Invalid configuration: Function "is_null" is not handled by the fixer.', ['replacements' => ['is_null' => 'random_int']], ]; yield 'wrong replacement' => [ '[random_api_migration] Invalid configuration: The option "replacements" with value array is expected to be of type "string[]", but one of the elements is of type "null".', ['replacements' => ['rand' => null]], ]; } public function testConfigure(): void { $this->fixer->configure(['replacements' => ['rand' => 'random_int']]); self::assertSame( ['replacements' => [ 'rand' => 'random_int', ]], \Closure::bind(static fn (RandomApiMigrationFixer $fixer): array => $fixer->configuration, null, RandomApiMigrationFixer::class)($this->fixer), ); } /** * @param _AutogeneratedInputConfiguration $config * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixCases(): iterable { yield [ ' ['rand' => 'random_int']], ]; yield [ ' ['rand' => 'random_int']], ]; yield ['srand($a);']; yield [' ['rand' => 'random_int']], ]; yield [ ' ['rand' => 'random_int']], ]; yield [ ' ['rand' => 'random_int']], ]; yield [ ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], ]; yield [ ' ['rand' => 'random_int']], ]; yield [ ' ['rand' => 'rand']], ]; yield [ ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], ]; yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield 'simple 8.1' => [ '