* 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\LanguageConstruct; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @internal * * @covers \PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer */ final class FunctionToConstantFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideTestCases */ public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } public function provideTestCases(): array { return [ 'Minimal case, alternative casing, alternative statement end.' => [ '', '', ], 'With embedded comment.' => [ '', '', ], 'With white space.' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'phpversion();', ], 'Overridden function.' => [ '', ], 'phpversion only' => [ ' ['phpversion']], ], 'php_sapi_name only' => [ ' ['php_sapi_name']], ], 'php_sapi_name in conditional' => [ ' ['php_sapi_name']], ], 'pi only' => [ ' ['pi']], ], 'multi line pi' => [ ' ['pi']], ], 'phpversion and pi' => [ ' ['pi', 'phpversion']], ], 'diff argument count than native allows' => [ ' T_CLASS' => [ ' [ ' ['get_called_class']], ], [ ' ['get_called_class']], ], 'get_called_class with leading backslash' => [ ' ['get_called_class']], ], 'get_called_class overridden' => [ ' ['get_called_class']], ], [ ' ['get_class_this']], ], [ ' ['get_class_this']], ], [ ' ['get_class_this']], ], [ ' ['get_class_this', 'get_class']], ], [ 'extension)); }} class Foo{ public function Bar(){ echo $reflection = new \ReflectionClass(get_class($this() )); }} ', null, ['functions' => ['get_class_this']], ], [ "expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[function_to_constant\] Invalid configuration: The option "functions" with value array is invalid\.$#'); $this->fixer->configure($config); } public function provideInvalidConfigurationKeysCases(): array { return [ [['functions' => ['a']]], [['functions' => [false => 1]]], [['functions' => ['abc' => true]]], ]; } public function testInvalidConfigurationValue(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[function_to_constant\] Invalid configuration: The option "0" does not exist\. Defined options are: "functions"\.$#'); $this->fixer->configure(['pi123']); } /** * @dataProvider provideFix81Cases * @requires PHP 8.1 */ public function testFix81(string $expected, string $input = null): void { $this->doTest($expected, $input); } public function provideFix81Cases(): \Generator { yield 'first callable class' => [ '