* 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\Whitespace; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** * @author Marc Aubé * * @internal * * @covers \PhpCsFixer\Fixer\Whitespace\SpacesInsideParenthesesFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Whitespace\SpacesInsideParenthesesFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Whitespace\SpacesInsideParenthesesFixer */ final class SpacesInsideParenthesesFixerTest extends AbstractFixerTestCase { public function testInvalidConfigMissingKey(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[spaces_inside_parentheses\] Invalid configuration: The option "a" does not exist\. Defined options are: "space"\.$#'); $this->fixer->configure(['a' => 1]); } public function testInvalidConfigValue(): void { $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[spaces_inside_parentheses\] Invalid configuration: The option "space" with value "double" is invalid\. Accepted values are: "none", "single"\.$#'); $this->fixer->configure(['space' => 'double']); // @phpstan-ignore-line } /** * @dataProvider provideDefaultFixCases */ public function testDefaultFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } /** * @dataProvider provideSpacesFixCases */ public function testSpacesFix(string $expected, ?string $input = null): void { $this->fixer->configure(['space' => 'single']); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideDefaultFixCases(): iterable { // default leaves new lines alone yield [ "bar($arg1, $arg2);', 'bar( $arg1, $arg2 );', ]; yield [ 'test( // do not remove space $e // between `(` and `)` // and this comment );', ]; yield [ 'bar();', 'bar();', ]; yield [ 'bar;', 'bar;', ]; } /** * @return iterable */ public static function provideSpacesFixCases(): iterable { // Leaves new lines alone yield [ "bar( $arg1, $arg2 );', 'bar( $arg1, $arg2 );', ]; yield [ 'test( // do not remove space $e // between `(` and `)` // and this comment );', ]; yield [ 'bar();', 'bar();', ]; } /** * @dataProvider provideDefaultFix80Cases * * @requires PHP 8.0 */ public function testDefaultFix80(string $expected, string $input): void { $this->doTest($expected, $input); } /** * @return iterable */ public static function provideDefaultFix80Cases(): iterable { yield 'mixed argument' => [ 'fixer->configure(['space' => 'single']); $this->doTest($expected, $input); } /** * @return iterable */ public static function provideSpacesFix80Cases(): iterable { yield 'mixed argument' => [ '