Browse Source

Fix tests

SpacePossum 4 years ago
parent
commit
bcfd44c0a0

+ 14 - 21
tests/Fixer/Alias/ArrayPushFixerTest.php

@@ -95,35 +95,25 @@ final class ArrayPushFixerTest extends AbstractFixerTestCase
             '<?php /* */ array_push($a2, $b3) /** */;',
         ];
 
-        yield [
-            '<?php $a5{1*3}[2+1][] = $b4{2+1};',
-            '<?php array_push($a5{1*3}[2+1], $b4{2+1});',
-        ];
-
         yield [
             '<?php $a4[1][] = $b6[2];',
             '<?php array_push($a4[1], $b6[2]);',
         ];
 
-        yield [
-            '<?php $a5{1*3}[2+1][] = $b7{2+1};',
-            '<?php array_push($a5{1*3}[2+1], $b7{2+1});',
-        ];
-
         yield 'case insensitive and precedence' => [
             '<?php
                 $a[] = $b--;
                 $a[] = ++$b;
                 $a[] = !$b;
                 $a[] = $b + $c;
-                $a[] = 1 ** $c / 2 || !b && c(1,2,3) ^ $a{1};
+                $a[] = 1 ** $c / 2 || !b && c(1,2,3) ^ $a[1];
             ',
             '<?php
                 array_push($a, $b--);
                 ARRAY_push($a, ++$b);
                 array_PUSH($a, !$b);
                 ARRAY_PUSH($a, $b + $c);
-                \array_push($a, 1 ** $c / 2 || !b && c(1,2,3) ^ $a{1});
+                \array_push($a, 1 ** $c / 2 || !b && c(1,2,3) ^ $a[1]);
             ',
         ];
 
@@ -208,13 +198,6 @@ final class ArrayPushFixerTest extends AbstractFixerTestCase
             '<?php namespace Foo; array_push($a + 1, $a16);',
         ];
 
-        yield [
-            '<?php
-                array_push(++foo()->bar, 1);
-                array_push(foo()->bar + 1, 1);
-            ',
-        ];
-
         yield 'different namespace and not a function call' => [
             '<?php
                 A\array_push($a, $b17);
@@ -232,8 +215,6 @@ final class ArrayPushFixerTest extends AbstractFixerTestCase
         ];
 
         $precedenceCases = [
-            '$b = yield $c',
-            '$b = yield from $c',
             '$b and $c',
             '$b or $c',
             '$b xor $c',
@@ -262,5 +243,17 @@ final class ArrayPushFixerTest extends AbstractFixerTestCase
                 if ($b) {} elseif (foo()) array_push($a, $b);
             ',
         ];
+
+        if (\PHP_VERSION_ID < 80000) {
+            yield [
+                '<?php $a5{1*3}[2+1][] = $b4{2+1};',
+                '<?php array_push($a5{1*3}[2+1], $b4{2+1});',
+            ];
+
+            yield [
+                '<?php $a5{1*3}[2+1][] = $b7{2+1};',
+                '<?php array_push($a5{1*3}[2+1], $b7{2+1});',
+            ];
+        }
     }
 }

+ 13 - 13
tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php

@@ -496,48 +496,48 @@ final class NoUnneededControlParenthesesFixerTest extends AbstractFixerTestCase
         return [
             [
                 '<?php
-                function foo() { yield from "prod"; }
+                function foo1() { yield from "prod"; }
                 ',
             ],
             [
                 '<?php
-                function foo() { yield from (1 + 2) * 10; }
+                function foo2() { yield from (1 + 2) * 10; }
 
-                function foo() { $a = (yield($x)); }
+                function foo3() { $a = (yield($x)); }
                 ',
             ],
             [
                 '<?php
-                function foo() { yield from (1 + 2) * 10; }
+                function foo4() { yield from (1 + 2) * 10; }
                 ',
                 '<?php
-                function foo() { yield from ((1 + 2) * 10); }
+                function foo4() { yield from ((1 + 2) * 10); }
                 ',
             ],
             [
                 '<?php
-                function foo() { yield from "prod"; }
-                function foo() { $a = (yield($x)); }
+                function foo5() { yield from "prod"; }
+                function foo6() { $a = (yield($x)); }
                 ',
                 '<?php
-                function foo() { yield from ("prod"); }
-                function foo() { $a = (yield($x)); }
+                function foo5() { yield from ("prod"); }
+                function foo6() { $a = (yield($x)); }
                 ',
             ],
             [
                 '<?php
-                function foo() { yield from 2; }
+                function foo7() { yield from 2; }
                 ',
                 '<?php
-                function foo() { yield from(2); }
+                function foo7() { yield from(2); }
                 ',
             ],
             [
                 '<?php
-                function foo() { $a = (yield from $x); }
+                function foo8() { $a = (yield from $x); }
                 ',
                 '<?php
-                function foo() { $a = (yield from($x)); }
+                function foo8() { $a = (yield from($x)); }
                 ',
             ],
         ];

+ 83 - 118
tests/Fixer/ControlStructure/SwitchContinueToBreakFixerTest.php

@@ -34,7 +34,7 @@ final class SwitchContinueToBreakFixerTest extends AbstractFixerTestCase
 
     public function provideTestFixCases()
     {
-        return [
+        $tests = [
             'alternative syntax |' => [
                 '<?php
                     switch($foo):
@@ -55,48 +55,6 @@ if ($foo != 0) {
 
 switch ($foo):
 endswitch;',
-            ],
-            'simple case' => [
-                '<?php
-switch($a) {
-    case 1:
-        echo 1;
-
-        break;
-    case 2:
-        echo 2;
-
-        if ($z) break 1;
-
-        break 1;
-    case 3:
-        echo 2;
-
-        continue 2;
-    case 4:
-        continue 12;
-}
-',
-                '<?php
-switch($a) {
-    case 1:
-        echo 1;
-
-        continue;
-    case 2:
-        echo 2;
-
-        if ($z) continue 1;
-
-        continue 1;
-    case 3:
-        echo 2;
-
-        continue 2;
-    case 4:
-        continue 12;
-}
-',
             ],
             'nested switches' => [
                 '<?php
@@ -134,52 +92,6 @@ switch($z) {
         }
         continue; // x
 }
-',
-            ],
-            'nested 1' => [
-                '<?php
-    while($a) {
-        switch($b) {
-            case 1:
-                break 1;
-            case 2:
-                break 1;
-            case 3:
-                continue 2;
-            case 4:
-                continue 3;
-        }
-    }
-
-    switch($b) {
-        case 1:
-            switch($c) {
-                case 1:
-                    break 2;
-        }
-    }
-',
-                '<?php
-    while($a) {
-        switch($b) {
-            case 1:
-                continue 1;
-            case 2:
-                continue 1;
-            case 3:
-                continue 2;
-            case 4:
-                continue 3;
-        }
-    }
-
-    switch($b) {
-        case 1:
-            switch($c) {
-                case 1:
-                    continue 2;
-        }
-    }
 ',
             ],
             'nested 2' => [
@@ -368,7 +280,7 @@ switch($a) {
             continue;
         }
 
-        while (false) continue 2;
+        while (false) break 1;
 
         do {
             continue;
@@ -379,7 +291,7 @@ switch($a) {
         }
 
         foreach ($a as $b) continue;
-        for (; $i < 1; ++$i) continue 7; echo $i;
+        for (; $i < 1; ++$i) break 1; echo $i;
         for (;;) continue;
         while(false) continue;
         while(false) continue?><?php
@@ -488,49 +400,102 @@ case $b:
 }}}}}}}}}}',
             ],
         ];
-    }
 
-    /**
-     * @param string      $expected
-     * @param null|string $input
-     *
-     * @dataProvider provideTestFixPhp70Cases
-     * @requires PHP 7.0
-     */
-    public function testFixPhp70($expected, $input = null)
-    {
-        $this->doTest($expected, $input);
-    }
+        foreach ($tests as $index => $test) {
+            yield $index => $test;
+        }
 
-    public function provideTestFixPhp70Cases()
-    {
-        return [
-            [
-                sprintf('<?php switch($a){ case 1: continue 1%d;}', PHP_INT_MAX),
-            ],
-            [
+        if (\PHP_VERSION_ID < 70000) {
+            yield 'simple case' => [
                 '<?php
 switch($a) {
     case 1:
-        continue $a;
+        echo 1;
+
+        break;
     case 2:
-        break 0;
+        echo 2;
+
+        if ($z) break 1;
+
+        break 1;
     case 3:
-        continue 1.2;
+        echo 2;
+
+        continue 2;
+    case 4:
+        continue 12;
 }
 ',
                 '<?php
 switch($a) {
     case 1:
-        continue $a;
+        echo 1;
+
+        continue;
     case 2:
-        continue 0;
+        echo 2;
+
+        if ($z) continue 1;
+
+        continue 1;
     case 3:
-        continue 1.2;
+        echo 2;
+
+        continue 2;
+    case 4:
+        continue 12;
 }
 ',
-            ],
-        ];
+            ];
+
+            yield 'nested 1' => [
+                '<?php
+    while($a) {
+        switch($b) {
+            case 1:
+                break 1;
+            case 2:
+                break 1;
+            case 3:
+                continue 2;
+            case 4:
+                continue 3;
+        }
+    }
+
+    switch($b) {
+        case 1:
+            switch($c) {
+                case 1:
+                    break 2;
+        }
+    }
+',
+                '<?php
+    while($a) {
+        switch($b) {
+            case 1:
+                continue 1;
+            case 2:
+                continue 1;
+            case 3:
+                continue 2;
+            case 4:
+                continue 3;
+        }
+    }
+
+    switch($b) {
+        case 1:
+            switch($c) {
+                case 1:
+                    continue 2;
+        }
+    }
+',
+            ];
+        }
     }
 
     /**

+ 15 - 10
tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php

@@ -132,9 +132,6 @@ $a = function() use ($b) { new class($b){}; }; // do not fix
 $a = function() use ($b) { new class(){ public function foo($b){echo $b;}}; }; // do fix
 ',
             ],
-            [
-                '<?php $fn = function() use ($this) {} ?>',
-            ],
         ];
     }
 
@@ -150,13 +147,10 @@ $a = function() use ($b) { new class(){ public function foo($b){echo $b;}}; }; /
 
     public function provideDoNotFixCases()
     {
-        return [
+        $tests = [
             'reference' => [
                 '<?php $fn = function() use(&$b) {} ?>',
             ],
-            'super global, invalid from PHP7.1' => [
-                '<?php $fn = function() use($_COOKIE) {} ?>',
-            ],
             'compact 1' => [
                 '<?php $foo = function() use ($b) { return compact(\'b\'); };',
             ],
@@ -166,9 +160,6 @@ $a = function() use ($b) { new class(){ public function foo($b){echo $b;}}; }; /
             'eval' => [
                 '<?php $foo = function($c) use ($b) { eval($c); };',
             ],
-            'super global' => [
-                '<?php $foo = function($c) use ($_COOKIE) {};',
-            ],
             'include' => [
                 '<?php $foo = function($c) use ($b) { include __DIR__."/test3.php"; };',
             ],
@@ -210,5 +201,19 @@ $foo();
 ',
             ],
         ];
+
+        foreach ($tests as $index => $test) {
+            yield $index => $test;
+        }
+
+        if (\PHP_VERSION_ID < 70100) {
+            yield 'super global, invalid from PHP7.1' => [
+                '<?php $fn = function() use($_COOKIE) {} ?>',
+            ];
+
+            yield 'super global' => [
+                '<?php $foo = function($c) use ($_COOKIE) {};',
+            ];
+        }
     }
 }

+ 20 - 7
tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php

@@ -72,12 +72,10 @@ final class RegularCallableCallFixerTest extends AbstractFixerTestCase
             '<?php
                 $c(1, 2);
                 $a["b"]["c"](1, 2);
-                $a["b"]{"c"}(1, 2);
             ',
             '<?php
                 call_user_func($c, 1, 2);
                 call_user_func($a["b"]["c"], 1, 2);
-                call_user_func($a["b"]{"c"}, 1, 2);
             ',
         ];
         yield 'call with comments' => [
@@ -117,6 +115,17 @@ final class RegularCallableCallFixerTest extends AbstractFixerTestCase
         yield 'unsafe repeated variable' => [
             '<?php call_user_func($foo, $foo = "bar");',
         ];
+
+        if (\PHP_VERSION_ID < 80000) {
+            yield 'call by variable' => [
+                '<?php
+                    $a{"b"}{"c"}(1, 2);
+                ',
+                '<?php
+                    call_user_func($a{"b"}{"c"}, 1, 2);
+                ',
+            ];
+        }
     }
 
     /**
@@ -162,17 +171,17 @@ final class RegularCallableCallFixerTest extends AbstractFixerTestCase
                 call_user_func(\'a\'.$a.$b, 1, 2);
                 ($a/**/.$b)(1, 2);
                 (function (){})();
-                ($a["b"]{"c"}->a)(1, 2, 3, 4);
+                ($a["b"]["c"]->a)(1, 2, 3, 4);
                 ($a::$b)(1, 2);
-                ($a[1]::$b[2]{3})([&$c], array(&$d));
+                ($a[1]::$b[2][3])([&$c], array(&$d));
             ',
             '<?php
                 call_user_func(\'a\'.$a.$b, 1, 2);
                 call_user_func($a/**/.$b, 1, 2);
                 \call_user_func(function (){});
-                call_user_func($a["b"]{"c"}->a, 1, 2, 3, 4);
+                call_user_func($a["b"]["c"]->a, 1, 2, 3, 4);
                 call_user_func($a::$b, 1, 2);
-                call_user_func($a[1]::$b[2]{3}, [&$c], array(&$d));
+                call_user_func($a[1]::$b[2][3], [&$c], array(&$d));
             ',
         ];
         yield [
@@ -180,7 +189,11 @@ final class RegularCallableCallFixerTest extends AbstractFixerTestCase
             '<?php call_user_func($a(1, 2), [&$x], array(&$z));',
         ];
         yield 'redeclare/override' => [
-            '<?php function call_user_func($foo){}',
+            '<?php
+                if (!function_exists("call_user_func")) {
+                    function call_user_func($foo){}
+                }
+            ',
         ];
     }
 }

+ 46 - 44
tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php

@@ -50,11 +50,6 @@ final class TernaryToElvisOperatorFixerTest extends AbstractFixerTestCase
             '<?php $a ? $a : 1; $a ? $a : 1; $a ? $a : 1; $a ? $a : 1; $a ? $a : 1; $a ? $a : 1; $a ? $a : 1;',
         ];
 
-        yield [
-            '<?php __FILE__.$a.$b{2}.$c->$a[0] ?  : 1;',
-            '<?php __FILE__.$a.$b{2}.$c->$a[0] ? __FILE__.$a.$b{2}.$c->$a[0] : 1;',
-        ];
-
         yield [
             '<?php $z = $z ?  : "a";',
             '<?php $z = $z ? $z : "a";',
@@ -265,51 +260,16 @@ final class TernaryToElvisOperatorFixerTest extends AbstractFixerTestCase
             '<?php foo($a ? $a : $b, $c ? $c : $d);',
         ];
 
-        yield [
-            '<?php $i = $bar{0}[1]{2}[3] ?  : $foo;',
-            '<?php $i = $bar{0}[1]{2}[3] ? $bar{0}[1]{2}[3] : $foo;',
-        ];
-
-        yield [
-            '<?php $z = $a[1][2] ?  : 1;',
-            '<?php $z = $a[1][2] ? $a[1][2] : 1;',
-        ];
-
-        yield [
-            '<?php $fooX = $bar{0}[1]{2}[3] ?  : $foo;',
-            '<?php $fooX = $bar{0}[1]{2}[3] ? $bar{0}[1]{2}[3] : $foo;',
-        ];
-
-        yield [
-            '<?php $k = $bar{0} ?  : $foo;',
-            '<?php $k = $bar{0} ? $bar{0} : $foo;',
-        ];
-
         yield [
             '<?php $j[$b ?  : $c];',
             '<?php $j[$b ? $b : $c];',
         ];
 
-        yield 'ignore different type of index braces' => [
-            '<?php $z = $a[1] ?  : 1;',
-            '<?php $z = $a[1] ? $a{1} : 1;',
-        ];
-
         yield [
             '<?php foo($a[0] ?  : $b[0], $c[0] ?  : $d[0]);',
             '<?php foo($a[0] ? $a[0] : $b[0], $c[0] ? $c[0] : $d[0]);',
         ];
 
-        yield [
-            '<?php $l[$b[0] ?  : $c[0]];',
-            '<?php $l[$b[0] ? $b{0} : $c[0]];',
-        ];
-
-        yield [
-            '<?php $l{$b{0} ?  : $c{0}};',
-            '<?php $l{$b{0} ? $b{0} : $c{0}};',
-        ];
-
         yield [
             '<?php $a + 1 ?    : $b;',
             '<?php $a + 1 ? $a + 1 : $b;',
@@ -418,10 +378,6 @@ EOT
             '<?php $foo4 = 1 + $bar[0] ? $bar[0] : $foo;',
         ];
 
-        yield [
-            '<?php $foo = $a->{$b} ? $bar{0} : $foo;',
-        ];
-
         yield [
             '<?php $foo = $bar ? $$bar : 1;',
         ];
@@ -466,6 +422,52 @@ EOT
             '<?= $a ?  : $b ?>',
             '<?= $a ? $a : $b ?>',
         ];
+
+        if (\PHP_VERSION_ID < 80000) {
+            yield [
+                '<?php $foo = $a->{$b} ? $bar{0} : $foo;',
+            ];
+
+            yield [
+                '<?php $l[$b[0] ?  : $c[0]];',
+                '<?php $l[$b[0] ? $b{0} : $c[0]];',
+            ];
+
+            yield [
+                '<?php $l{$b{0} ?  : $c{0}};',
+                '<?php $l{$b{0} ? $b{0} : $c{0}};',
+            ];
+
+            yield [
+                '<?php $z = $a[1][2] ?  : 1;',
+                '<?php $z = $a[1][2] ? $a[1][2] : 1;',
+            ];
+
+            yield [
+                '<?php $i = $bar{0}[1]{2}[3] ?  : $foo;',
+                '<?php $i = $bar{0}[1]{2}[3] ? $bar{0}[1]{2}[3] : $foo;',
+            ];
+
+            yield [
+                '<?php $fooX = $bar{0}[1]{2}[3] ?  : $foo;',
+                '<?php $fooX = $bar{0}[1]{2}[3] ? $bar{0}[1]{2}[3] : $foo;',
+            ];
+
+            yield [
+                '<?php $k = $bar{0} ?  : $foo;',
+                '<?php $k = $bar{0} ? $bar{0} : $foo;',
+            ];
+
+            yield 'ignore different type of index braces' => [
+                '<?php $z = $a[1] ?  : 1;',
+                '<?php $z = $a[1] ? $a{1} : 1;',
+            ];
+
+            yield [
+                '<?php __FILE__.$a.$b{2}.$c->$a[0] ?  : 1;',
+                '<?php __FILE__.$a.$b{2}.$c->$a[0] ? __FILE__.$a.$b{2}.$c->$a[0] : 1;',
+            ];
+        }
     }
 
     /**

+ 1 - 1
tests/Fixtures/Integration/set/@PHP74Migration.test

@@ -3,4 +3,4 @@ Integration of @PHP74Migration.
 --RULESET--
 {"@PHP74Migration": true}
 --REQUIREMENTS--
-{"php": 70400}
+{"php": 70400, "php<": 80000}