123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\Operator;
- use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\Operator\ConcatSpaceFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\ConcatSpaceFixer>
- *
- * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Operator\ConcatSpaceFixer
- */
- final class ConcatSpaceFixerTest extends AbstractFixerTestCase
- {
- public function testInvalidConfigMissingKey(): void
- {
- $this->expectException(InvalidFixerConfigurationException::class);
- $this->expectExceptionMessageMatches('#^\[concat_space\] Invalid configuration: The option "a" does not exist\. Defined options are: "spacing"\.$#');
- $this->fixer->configure(['a' => 1]);
- }
- public function testInvalidConfigValue(): void
- {
- $this->expectException(InvalidFixerConfigurationException::class);
- $this->expectExceptionMessageMatches('#^\[concat_space\] Invalid configuration: The option "spacing" with value "tabs" is invalid\. Accepted values are: "one", "none"\.$#');
- $this->fixer->configure(['spacing' => 'tabs']); // @phpstan-ignore-line
- }
- /**
- * @dataProvider provideFixWithoutSpaceCases
- */
- public function testFixWithoutSpace(string $expected, ?string $input = null): void
- {
- $this->fixer->configure(['spacing' => 'none']);
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string}>
- */
- public static function provideFixWithoutSpaceCases(): iterable
- {
- yield [
- '<?php $foo = "a".\'b\'."c"."d".$e.($f + 1);',
- '<?php $foo = "a" . \'b\' ."c". "d" . $e.($f + 1);',
- ];
- yield [
- '<?php $foo = 1 ."foo";',
- '<?php $foo = 1 . "foo";',
- ];
- yield [
- '<?php $foo = "foo". 1;',
- '<?php $foo = "foo" . 1;',
- ];
- yield [
- '<?php $foo = "a".
- "b";',
- '<?php $foo = "a" .
- "b";',
- ];
- yield [
- '<?php $a = "foobar"
- ."baz";',
- ];
- yield [
- '<?php $a = "foobar"
- //test
- ."baz";',
- ];
- yield [
- '<?php $a = "foobar"
- /* test */
- ."baz";',
- ];
- yield [
- '<?php $a = "foobar" //
- ."baz";',
- ];
- yield [
- '<?php $a = "foobar" //
- ."baz"//
- ."cex"/**/
- ."dev"/** */
- ."baz" //
- ."cex" /**/
- ."ewer23" '.'
- ."dev" /** */
- ;',
- ];
- yield [
- '<?php $a = "foobar" //
- ."baz" /**/
- ."something";',
- ];
- yield [
- '<?php $a = "foobar"
- ."baz". //
- "something";',
- ];
- yield [
- '<?php $a = "foobar"
- ."baz". /** */
- "something";',
- ];
- yield [
- "<?php
- \$longString = '*'
- .'*****'
- .'*****'
- .'*****'
- // Comment about next line
- .'*****'
- // Other comment
- .'*****';
- ",
- "<?php
- \$longString = '*'
- . '*****'
- . '*****'
- . '*****'
- // Comment about next line
- . '*****'
- // Other comment
- . '*****';
- ",
- ];
- }
- /**
- * @dataProvider provideFixWithSpaceCases
- */
- public function testFixWithSpace(string $expected, ?string $input = null): void
- {
- $this->fixer->configure(['spacing' => 'one']);
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{string, string}>
- */
- public static function provideFixWithSpaceCases(): iterable
- {
- yield [
- '<?php
- $a = //
- $c . /**/
- $d #
- . $e /** */
- . $f . //
- $z;
- ',
- '<?php
- $a = //
- $c . /**/
- $d #
- . $e /** */
- . $f . //
- $z;
- ',
- ];
- yield [
- '<?php $foo = "a" . \'b\' . "c" . "d" . $e . ($f + 1);',
- '<?php $foo = "a" . \'b\' ."c". "d" . $e.($f + 1);',
- ];
- yield [
- '<?php $foo = "a" .
- "b";',
- '<?php $foo = "a".
- "b";',
- ];
- yield [
- '<?php $a = "foobar"
- . "baz";',
- '<?php $a = "foobar"
- ."baz";',
- ];
- yield [
- '<?php echo $a . $b;
- echo $d . $e . //
- $f;
- echo $a . $b?>
- <?php
- echo $c;
- ',
- '<?php echo $a.$b;
- echo $d . $e . //
- $f;
- echo $a . $b?>
- <?php
- echo $c;
- ',
- ];
- }
- }
|