* 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\Fixer\Alias\ModernizeStrposFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Alexander M. Turek * * @internal * * @covers \PhpCsFixer\Fixer\Alias\ModernizeStrposFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Alias\ModernizeStrposFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Alias\ModernizeStrposFixer */ final class ModernizeStrposFixerTest extends AbstractFixerTestCase { public function testConfigure(): void { $this->fixer->configure(['modernize_stripos' => true]); self::assertSame( ['modernize_stripos' => true], \Closure::bind(static fn (ModernizeStrposFixer $fixer): array => $fixer->configuration, null, ModernizeStrposFixer::class)($this->fixer) ); } public function testInvalidConfiguration(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage('[modernize_strpos] Invalid configuration: The option "invalid" does not exist. Defined options are: "modernize_stripos".'); $this->fixer->configure(['invalid' => true]); } /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFixCases(): iterable { yield 'yoda ===' => [ ' [ ' true], ]; yield 'not zero yoda !==' => [ ' [ ' true], ]; yield 'false yoda ===' => [ ' [ ' true], ]; yield [ ' true], ]; yield 'casing call' => [ ' [ ' true], ]; yield 'leading namespace' => [ ' [ ' true], ]; yield 'leading namespace with yoda' => [ ' [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield 'casing operand' => [ ' [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield 'comments inside, no spacing' => [ ' [ ' true], ]; yield [ '', '', ]; yield [ '', '', ['modernize_stripos' => true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; yield [ ' true], ]; // do not fix yield [ ' [ ' [ ' false], ]; yield 'different namespace' => [ ' [ ' [ ' [ ' [ ' [ ' [ '', ]; yield 'case insensitive non condition' => [ '', ]; yield 'none zero int' => [ ' [ ' [ ' 0) {}', ]; yield 'case insensitive greater condition' => [ ' 0) {}', ]; yield 'lesser condition' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' $b;', ]; yield 'case insensitive higher precedence 4' => [ ' $b;', ]; } }