* 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\Tests\Test\AbstractFixerTestCase; /** * @author Vladimir Reznichenko * * @internal * * @covers \PhpCsFixer\AbstractFunctionReferenceFixer * @covers \PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer */ final class RandomApiMigrationFixerTest extends AbstractFixerTestCase { public function testConfigureCheckSearchFunction() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp('#^\[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() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp('#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "NULL" given\.$#'); $this->fixer->configure(['replacements' => ['rand' => null]]); } public function testConfigure() { $this->fixer->configure(['replacements' => ['rand' => 'random_int']]); $this->assertSame( ['replacements' => [ 'rand' => ['alternativeName' => 'random_int', 'argumentCount' => [0, 2]], ], ], static::getObjectAttribute($this->fixer, 'configuration') ); } /** * @param string $expected * @param null|string $input * @param array $config * * @dataProvider provideFixCases */ public function testFix($expected, $input = null, array $config = []) { $this->fixer->configure($config); $this->doTest($expected, $input); } /** * @return array[] */ public function provideFixCases() { return [ [ ' ['rand' => 'random_int']], ], [ ' ['rand' => 'random_int']], ], ['srand($a);'], [' ['rand' => 'random_int']], ], [ ' ['rand' => 'random_int']], ], [ ' ['rand' => 'random_int']], ], [ ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], ], [ ' ['rand' => 'random_int']], ], ]; } }