* 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\ClassNotation; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer */ final class VisibilityRequiredFixerTest extends AbstractFixerTestCase { /** * @param _AutogeneratedInputConfiguration $configuration * * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { $this->fixer->configure($configuration); $this->doTest($expected, $input); } public static function provideFixCases(): iterable { yield 'properties' => [ <<<'EOF' [ <<<'EOF' [ <<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF'
[<<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF' [<<<'EOF' EOF]; yield 'leave JavaScript in string alone' => [<<<'EOF' function foo(bar) { alert(bar); } '; } EOF]; yield 'leave JavaScript in variable alone' => [<<<'EOF' function foo(bar) { alert(bar); } JAVASCRIPT; return $script; } } EOF]; yield 'comma separated properties' => [<<<'EOF' [<<<'EOF' ['const']], ]; yield [ ' ['const']], ]; yield [ ' ['const']], ]; yield [ ' ['const']], ]; yield 'comment' => [ ' [ ' [ ' [ ' ['property', 'method', 'const']], ]; yield 'fixing with all keywords' => [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix80Cases(): iterable { yield [ 'doTest($expected, $input); } /** * @return iterable */ public static function provideFix81Cases(): iterable { yield [ 'test());', 'test());', ]; } /** * @requires PHP 8.2 * * @dataProvider provideFix82Cases */ public function testFix82(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideFix82Cases(): iterable { yield [ 'expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches($expectedMessage); $this->fixer->configure($config); } /** * @return iterable, string}> */ public static function provideInvalidConfigurationCases(): iterable { yield 'invalid type' => [ ['elements' => [null]], '/^\[visibility_required\] Invalid configuration: The option "elements" .*\.$/', ]; yield 'invalid value' => [ ['elements' => ['_unknown_']], '/^\[visibility_required\] Invalid configuration: The option "elements" .*\.$/', ]; } }