* 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 { /** * @param array $config * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield 'Minimal case, alternative casing, alternative statement end.' => [ '', '', ]; yield 'With embedded comment.' => [ '', '', ]; yield 'With white space.' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'phpversion();', ]; yield 'Overridden function.' => [ '', ]; yield 'phpversion only' => [ ' ['phpversion']], ]; yield 'php_sapi_name only' => [ ' ['php_sapi_name']], ]; yield 'php_sapi_name in conditional' => [ ' ['php_sapi_name']], ]; yield 'pi only' => [ ' ['pi']], ]; yield 'multi line pi' => [ ' ['pi']], ]; yield 'phpversion and pi' => [ ' ['pi', 'phpversion']], ]; yield 'diff argument count than native allows' => [ ' T_CLASS' => [ ' [ ' ['get_called_class']], ]; yield [ ' ['get_called_class']], ]; yield 'get_called_class with leading backslash' => [ ' ['get_called_class']], ]; yield 'get_called_class overridden' => [ ' ['get_called_class']], ]; yield [ ' ['get_class_this']], ]; yield [ ' ['get_class_this']], ]; yield [ ' ['get_class_this']], ]; yield [ ' ['get_class_this', 'get_class']], ]; yield [ 'extension)); }} class Foo{ public function Bar(){ echo $reflection = new \ReflectionClass(get_class($this() )); }} ', null, ['functions' => ['get_class_this']], ]; yield [ " $config * * @dataProvider provideInvalidConfigurationKeysCases */ public function testInvalidConfigurationKeys(array $config): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[function_to_constant\] Invalid configuration: The option "functions" with value array is invalid\.$#'); $this->fixer->configure($config); } public static function provideInvalidConfigurationKeysCases(): iterable { yield [['functions' => ['a']]]; yield [['functions' => [false => 1]]]; yield [['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"\.$#'); // @phpstan-ignore-next-line $this->fixer->configure(['pi123']); } /** * @dataProvider provideFix81Cases * * @requires PHP 8.1 */ public function testFix81(string $expected, string $input = null): void { $this->doTest($expected, $input); } public static function provideFix81Cases(): iterable { yield 'first callable class' => [ '