Skip to content

Commit

Permalink
chore: do not check PHP_VERSION_ID (#7602)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Dec 20, 2023
1 parent 27765a6 commit 3de82d3
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 238 deletions.
75 changes: 44 additions & 31 deletions tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,31 +598,8 @@ class X10 implements Z , T,R //
['start' => 5, 'numberOfImplements' => 3, 'multiLine' => false],
];

if (\PHP_VERSION_ID < 8_00_00) {
$multiLine = true;
$code = '<?php
namespace A {
interface X {}
}
namespace {
class B{}
class A extends //
B implements /* */ \A
\C, Z{
public function test()
{
echo 1;
}
}
$a = new A();
$a->test();
}';
} else {
$multiLine = false;
$code = '<?php
yield [
'<?php
namespace A {
interface X {}
}
Expand All @@ -640,13 +617,9 @@ public function test()
$a = new A();
$a->test();
}';
}

yield [
$code,
}',
'numberOfImplements',
['start' => 36, 'numberOfImplements' => 2, 'multiLine' => $multiLine],
['start' => 36, 'numberOfImplements' => 2, 'multiLine' => false],
];

yield [
Expand All @@ -668,6 +641,46 @@ public function test()
];
}

/**
* @param array<string, mixed> $expected
*
* @dataProvider provideClassyInheritanceInfoPre80Cases
*
* @requires PHP <8.0
*/
public function testClassyInheritanceInfoPre80(string $source, string $label, array $expected): void
{
$this->doTestClassyInheritanceInfo($source, $label, $expected);
}

public static function provideClassyInheritanceInfoPre80Cases(): iterable
{
yield [
'<?php
namespace A {
interface X {}
}
namespace {
class B{}
class A extends //
B implements /* */ \A
\C, Z{
public function test()
{
echo 1;
}
}
$a = new A();
$a->test();
}',
'numberOfImplements',
['start' => 36, 'numberOfImplements' => 2, 'multiLine' => true],
];
}

/**
* @dataProvider provideWithWhitespacesConfigCases
*/
Expand Down
49 changes: 30 additions & 19 deletions tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,33 +588,44 @@ public function & strlen($name) {
'include' => [NativeFunctionInvocationFixer::SET_ALL],
],
];
}

/**
* @param array<string, mixed> $configuration
*
* @dataProvider provideFixPre80Cases
*
* @requires PHP <8.0
*/
public function testFixPre80(string $expected, ?string $input = null, array $configuration = []): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}

if (\PHP_VERSION_ID < 8_00_00) {
yield 'include @compiler_optimized with strict enabled' => [
'<?php
/**
* @return iterable<array{string, 1?: string, 2?: array<mixed>}>
*/
public static function provideFixPre80Cases(): iterable
{
yield 'include @compiler_optimized with strict enabled' => [
'<?php
$a = not_compiler_optimized_function();
$b = not_compiler_optimized_function();
$c = \intval($d);
',
'<?php
'<?php
$a = \not_compiler_optimized_function();
$b = \ not_compiler_optimized_function();
$c = intval($d);
',
[
'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
'strict' => true,
],
];
}
}
[
'include' => [NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED],
'strict' => true,
],
];

/**
* @requires PHP <8.0
*/
public function testFixPrePHP80(): void
{
$this->doTest(
yield [
'<?php
echo \/**/strlen($a);
echo \ strlen($a);
Expand All @@ -630,8 +641,8 @@ public function testFixPrePHP80(): void
#
strlen($a);
echo strlen($a);
'
);
',
];
}

/**
Expand Down
36 changes: 25 additions & 11 deletions tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ public static function provideFixCases(): iterable
'<?php call_user_func($foo, $foo = "bar");',
];

if (\PHP_VERSION_ID < 8_00_00) {
yield 'call by variable (PHP < 8.0)' => [
'<?php
$a{"b"}{"c"}(1, 2);
',
'<?php
call_user_func($a{"b"}{"c"}, 1, 2);
',
];
}

yield 'call by property' => [
'<?php
($f->c)(1, 2);
Expand Down Expand Up @@ -241,6 +230,31 @@ public static function createFromFactory(...$args) {
];
}

/**
* @dataProvider provideFixPre80Cases
*
* @requires PHP <8.0
*/
public function testFixPre80(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<array{string, 1?: string}>
*/
public static function provideFixPre80Cases(): iterable
{
yield 'call by variable' => [
'<?php
$a{"b"}{"c"}(1, 2);
',
'<?php
call_user_func($a{"b"}{"c"}, 1, 2);
',
];
}

/**
* @dataProvider provideFix81Cases
*
Expand Down
23 changes: 11 additions & 12 deletions tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ public static function provideFixCases(): iterable
'<?php unset($this->property[array_search(\Types::TYPE_RANDOM, $this->property)]);',
];

if (\PHP_VERSION_ID < 8_00_00) {
yield 'It does not replace unsets on arrays with special notation' => [
'<?php unset($bar->foo{0});',
];
}

yield 'It does not break complex expressions' => [
'<?php
unset(a()[b()["a"]]);
Expand Down Expand Up @@ -231,12 +225,6 @@ public static function provideFixCases(): iterable
'<?php $foo->bar = null ;',
'<?php unset($foo->bar , );',
];

if (\PHP_VERSION_ID < 8_00_00) {
yield 'It does not replace unsets on arrays with special notation 1' => [
'<?php unset($bar->foo{0},);',
];
}
}

/**
Expand All @@ -249,8 +237,19 @@ public function testFixPre80(string $expected, string $input = null): void
$this->doTest($expected, $input);
}

/**
* @return iterable<array{string}>
*/
public static function provideFixPre80Cases(): iterable
{
yield 'It does not replace unsets on arrays with special notation' => [
'<?php unset($bar->foo{0});',
];

yield 'It does not replace unsets on arrays with special notation 1' => [
'<?php unset($bar->foo{0},);',
];

yield 'It does not break curly access expressions' => [
'<?php unset(a(){"a"});',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,6 @@ public static function provideFixCases(): iterable
'<?php $a = $a ?? $b ? $c : $d ?>',
];

if (\PHP_VERSION_ID < 8_00_00) {
yield 'mixed array' => [
'<?php
$a[1] ??= 1;
$a{2} ??= 1;
$a{2}[$f] ??= 1;
',
'<?php
$a[1] = $a[1] ?? 1;
$a{2} = $a{2} ?? 1;
$a{2}[$f] = $a{2}[$f] ?? 1;
',
];

yield 'same II' => [
'<?php $a[1] ??= 1;',
'<?php $a[1] = $a{1} ?? 1;',
];

yield 'same III' => [
'<?php $a[1] ??= 1;',
'<?php $a[1] = (($a{1})) ?? 1;',
];
}

yield ['<?php $a[1][0] = $a ?? $a[1][0];'];

yield 'switch case & default' => [
Expand Down Expand Up @@ -272,4 +247,43 @@ public function bar($i)
}',
];
}

/**
* @dataProvider provideFixPre80Cases
*
* @requires PHP <8.0
*/
public function testFixPre80(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<string, array{string, 1?: string}>
*/
public static function provideFixPre80Cases(): iterable
{
yield 'mixed array' => [
'<?php
$a[1] ??= 1;
$a{2} ??= 1;
$a{2}[$f] ??= 1;
',
'<?php
$a[1] = $a[1] ?? 1;
$a{2} = $a{2} ?? 1;
$a{2}[$f] = $a{2}[$f] ?? 1;
',
];

yield 'same II' => [
'<?php $a[1] ??= 1;',
'<?php $a[1] = $a{1} ?? 1;',
];

yield 'same III' => [
'<?php $a[1] ??= 1;',
'<?php $a[1] = (($a{1})) ?? 1;',
];
}
}
46 changes: 30 additions & 16 deletions tests/Fixer/Operator/IncrementStyleFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,36 @@ public function foo() {
'<?php if ($foo) ++$a;',
'<?php if ($foo) $a++;',
];
}

if (\PHP_VERSION_ID < 8_00_00) {
yield [
'<?php ++$a->$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h;',
'<?php $a->$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h++;',
];

yield [
'<?php ++$a{0};',
'<?php $a{0}++;',
];

yield [
'<?php ++${$a}->{$b."foo"}->bar[$c]->$baz;',
'<?php ${$a}->{$b."foo"}->bar[$c]->$baz++;',
];
}
/**
* @dataProvider provideFixPre80Cases
*
* @requires PHP <8.0
*/
public function testFixPre80(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<array{string, 1?: string}>
*/
public static function provideFixPre80Cases(): iterable
{
yield [
'<?php ++$a->$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h;',
'<?php $a->$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h++;',
];

yield [
'<?php ++$a{0};',
'<?php $a{0}++;',
];

yield [
'<?php ++${$a}->{$b."foo"}->bar[$c]->$baz;',
'<?php ${$a}->{$b."foo"}->bar[$c]->$baz++;',
];
}
}
Loading

0 comments on commit 3de82d3

Please sign in to comment.