* 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\Tests\Test\AbstractFixerTestCase; /** * @author Vladimir Reznichenko * * @internal * * @covers \PhpCsFixer\AbstractFunctionReferenceFixer * @covers \PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer */ final class RandomApiMigrationFixerTest extends AbstractFixerTestCase { public function testConfigureCheckSearchFunction(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Function "is_null" is not handled by the fixer\.$#'); $this->fixer->configure(['replacements' => ['is_null' => 'random_int']]); } public function testConfigureCheckReplacementType(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "null" given\.$#'); $this->fixer->configure(['replacements' => ['rand' => null]]); } public function testConfigure(): void { $this->fixer->configure(['replacements' => ['rand' => 'random_int']]); $reflectionProperty = new \ReflectionProperty($this->fixer, 'configuration'); $reflectionProperty->setAccessible(true); self::assertSame( ['replacements' => [ 'rand' => ['alternativeName' => 'random_int', 'argumentCount' => [0, 2]], ], ], $reflectionProperty->getValue($this->fixer) ); } /** * @param array $config * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } /** * @return array[] */ 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); } public static function provideFix81Cases(): iterable { yield 'simple 8.1' => [ '