* 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\Tests\Test\AbstractFixerTestCase; /** * @author SpacePossum * * @internal * * @covers \PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer */ final class FunctionToConstantFixerTest extends AbstractFixerTestCase { /** * @param string $expected * @param null|string $input * @param null|array $config * * @dataProvider provideTestCases */ public function testFix($expected, $input = null, array $config = null) { if ($config) { $this->fixer->configure($config); } $this->doTest($expected, $input); } public function provideTestCases() { 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' => [ ' [ 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp('#^\[function_to_constant\] Invalid configuration: The option "functions" with value array is invalid\.$#'); $this->fixer->configure($config); } public function provideInvalidConfigurationKeysCases() { return [ [['functions' => ['a']]], [['functions' => [false => 1]]], [['functions' => ['abc' => true]]], ]; } public function testInvalidConfigurationValue() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp('#^\[function_to_constant\] Invalid configuration: The option "0" does not exist\. Defined options are: "functions"\.$#'); $this->fixer->configure(['pi123']); } }