Skip to content

Commit

Permalink
minor #5186 Fix tests (SpacePossum)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.17-dev branch.

Discussion
----------

Fix tests

Commits
-------

bcfd44c Fix tests
  • Loading branch information
SpacePossum committed Oct 19, 2020
2 parents 6d7da91 + bcfd44c commit 7a4f113
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 214 deletions.
35 changes: 14 additions & 21 deletions tests/Fixer/Alias/ArrayPushFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,25 @@ public function provideFixCases()
'<?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]);
',
];

Expand Down Expand Up @@ -208,13 +198,6 @@ public function provideFixCases()
'<?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);
Expand All @@ -232,8 +215,6 @@ public function provideFixCases()
];

$precedenceCases = [
'$b = yield $c',
'$b = yield from $c',
'$b and $c',
'$b or $c',
'$b xor $c',
Expand Down Expand Up @@ -262,5 +243,17 @@ public function provideFixCases()
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});',
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,48 +496,48 @@ public function provideFixYieldFromCases()
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)); }
',
],
];
Expand Down
201 changes: 83 additions & 118 deletions tests/Fixer/ControlStructure/SwitchContinueToBreakFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testFix($expected, $input = null)

public function provideTestFixCases()
{
return [
$tests = [
'alternative syntax |' => [
'<?php
switch($foo):
Expand All @@ -55,48 +55,6 @@ public function provideTestFixCases()
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
Expand Down Expand Up @@ -134,52 +92,6 @@ public function provideTestFixCases()
}
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' => [
Expand Down Expand Up @@ -368,7 +280,7 @@ public function provideTestFixCases()
continue;
}
while (false) continue 2;
while (false) break 1;
do {
continue;
Expand All @@ -379,7 +291,7 @@ public function provideTestFixCases()
}
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
Expand Down Expand Up @@ -488,49 +400,102 @@ public function provideTestFixCases()
}}}}}}}}}}',
],
];
}

/**
* @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;
}
}
',
];
}
}

/**
Expand Down
Loading

0 comments on commit 7a4f113

Please sign in to comment.