Просмотр исходного кода

minor #4602 Ensure compatibility with PHP 7.4 spread operator in array expression (julienfalque)

This PR was merged into the 2.15 branch.

Discussion
----------

Ensure compatibility with PHP 7.4 spread operator in array expression

Related to #4382.

Commits
-------

1f34525a Ensure compatibility with PHP 7.4 spread operator in array expression
Dariusz Ruminski 5 лет назад
Родитель
Сommit
47b0ef50cf

+ 26 - 0
tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php

@@ -140,4 +140,30 @@ TWIG
             ],
         ];
     }
+
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFixPhp74Cases
+     * @requires PHP 7.4
+     */
+    public function testFixPhp74($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixPhp74Cases()
+    {
+        return [
+            [
+                '<?php $x = array(...$foo);',
+                '<?php $x = array(...$foo, );',
+            ],
+            [
+                '<?php $x = [...$foo];',
+                '<?php $x = [...$foo, ];',
+            ],
+        ];
+    }
 }

+ 26 - 0
tests/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixerTest.php

@@ -175,4 +175,30 @@ EOF
             ],
         ];
     }
+
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFixPhp74Cases
+     * @requires PHP 7.4
+     */
+    public function testFixPhp74($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixPhp74Cases()
+    {
+        return [
+            [
+                '<?php $x = array(...$foo, ...$bar);',
+                '<?php $x = array(...$foo , ...$bar);',
+            ],
+            [
+                '<?php $x = [...$foo, ...$bar];',
+                '<?php $x = [...$foo , ...$bar];',
+            ],
+        ];
+    }
 }

+ 38 - 0
tests/Fixer/ArrayNotation/TrailingCommaInMultilineArrayFixerTest.php

@@ -394,4 +394,42 @@ INPUT
             ],
         ];
     }
+
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFixPhp74Cases
+     * @requires PHP 7.4
+     */
+    public function testFixPhp74($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixPhp74Cases()
+    {
+        return [
+            [
+                '<?php $x = array(
+                    ...$foo,
+                    ...$bar,
+                );',
+                '<?php $x = array(
+                    ...$foo,
+                    ...$bar
+                );',
+            ],
+            [
+                '<?php $x = [
+                    ...$foo,
+                    ...$bar,
+                ];',
+                '<?php $x = [
+                    ...$foo,
+                    ...$bar
+                ];',
+            ],
+        ];
+    }
 }

+ 26 - 0
tests/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixerTest.php

@@ -115,4 +115,30 @@ final class WhitespaceAfterCommaInArrayFixerTest extends AbstractFixerTestCase
             ],
         ];
     }
+
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFixPhp74Cases
+     * @requires PHP 7.4
+     */
+    public function testFixPhp74($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixPhp74Cases()
+    {
+        return [
+            [
+                '<?php $x = array(...$foo, ...$bar);',
+                '<?php $x = array(...$foo,...$bar);',
+            ],
+            [
+                '<?php $x = [...$foo, ...$bar];',
+                '<?php $x = [...$foo,...$bar];',
+            ],
+        ];
+    }
 }

+ 36 - 0
tests/Fixer/Whitespace/ArrayIndentationFixerTest.php

@@ -789,6 +789,42 @@ INPUT
         ]);
     }
 
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFixPhp74Cases
+     * @requires PHP 7.4
+     */
+    public function testFixPhp74($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixPhp74Cases()
+    {
+        return [
+            [
+                <<<'EXPECTED'
+<?php
+$foo = [
+    ...$foo,
+    ...$bar,
+];
+EXPECTED
+                ,
+                <<<'INPUT'
+<?php
+$foo = [
+  ...$foo,
+        ...$bar,
+ ];
+INPUT
+                ,
+            ],
+        ];
+    }
+
     private function withLongArraySyntaxCases(array $cases)
     {
         $longSyntaxCases = [];