diff --git a/packages/Php/src/Rector/BinaryOp/IsCountableRector.php b/packages/Php/src/Rector/BinaryOp/IsCountableRector.php index 6d78109f6fd..771285d8900 100644 --- a/packages/Php/src/Rector/BinaryOp/IsCountableRector.php +++ b/packages/Php/src/Rector/BinaryOp/IsCountableRector.php @@ -61,10 +61,10 @@ CODE_SAMPLE private function shouldSkip(): bool { - if ($this->isAtLeastPhpVersion('7.3')) { + if (function_exists('is_countable')) { return false; } - return ! function_exists('is_countable'); + return $this->isAtLeastPhpVersion('7.3'); } } diff --git a/packages/Php/src/Rector/BinaryOp/IsIterableRector.php b/packages/Php/src/Rector/BinaryOp/IsIterableRector.php index 53cfaf4df4a..22e1389cb13 100644 --- a/packages/Php/src/Rector/BinaryOp/IsIterableRector.php +++ b/packages/Php/src/Rector/BinaryOp/IsIterableRector.php @@ -61,10 +61,10 @@ CODE_SAMPLE private function shouldSkip(): bool { - if ($this->isAtLeastPhpVersion('7.1')) { + if (function_exists('is_iterable')) { return false; } - return ! function_exists('is_iterable'); + return $this->isAtLeastPhpVersion('7.1'); } } diff --git a/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture71.php.inc b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture71.php.inc new file mode 100644 index 00000000000..293b56d1796 --- /dev/null +++ b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture71.php.inc @@ -0,0 +1,8 @@ + diff --git a/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture.php.inc b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture73.php.inc similarity index 100% rename from packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture.php.inc rename to packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/fixture73.php.inc diff --git a/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/polyfill_function.php.inc b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/polyfill_function.php.inc new file mode 100644 index 00000000000..072a2ed88a6 --- /dev/null +++ b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/Fixture/polyfill_function.php.inc @@ -0,0 +1,47 @@ + +----- + diff --git a/packages/Php/tests/Rector/BinaryOp/IsCountableRector/IsCountableRectorTest.php b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/IsCountableRectorTest.php index c2760eba8c2..dbcade9cc86 100644 --- a/packages/Php/tests/Rector/BinaryOp/IsCountableRector/IsCountableRectorTest.php +++ b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/IsCountableRectorTest.php @@ -9,7 +9,13 @@ final class IsCountableRectorTest extends AbstractRectorTestCase { public function test(): void { - $this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc']); + // That method can be provided by `symfony/polyfill-php73` package, + // or not exists as it's run on PHP < 7.3 + if (! function_exists('is_countable')) { + $this->doTestFiles([__DIR__ . '/Fixture/fixture71.php.inc']); + } else { + $this->doTestFiles([__DIR__ . '/Fixture/fixture73.php.inc']); + } } public function getRectorClass(): string diff --git a/packages/Php/tests/Rector/BinaryOp/IsCountableRector/PolyfillRectorTest.php b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/PolyfillRectorTest.php new file mode 100644 index 00000000000..9caf5963fe3 --- /dev/null +++ b/packages/Php/tests/Rector/BinaryOp/IsCountableRector/PolyfillRectorTest.php @@ -0,0 +1,48 @@ +parameterProvider = self::$container->get(ParameterProvider::class); + $this->originalPhpVersionFeaturesParameter = $this->parameterProvider->provideParameter( + Option::PHP_VERSION_FEATURES + ); + + $this->parameterProvider->changeParameter(Option::PHP_VERSION_FEATURES, '7.2'); + } + + protected function tearDown(): void + { + parent::tearDown(); + + $this->parameterProvider->changeParameter( + Option::PHP_VERSION_FEATURES, + $this->originalPhpVersionFeaturesParameter + ); + } + + public function test(): void + { + $this->doTestFiles([__DIR__ . '/Fixture/polyfill_function.php.inc']); + } + + public function getRectorClass(): string + { + return IsCountableRector::class; + } +} diff --git a/packages/Php/tests/Rector/BinaryOp/IsIterableRector/Fixture/polyfil_function.php.inc b/packages/Php/tests/Rector/BinaryOp/IsIterableRector/Fixture/polyfill_function.php.inc similarity index 100% rename from packages/Php/tests/Rector/BinaryOp/IsIterableRector/Fixture/polyfil_function.php.inc rename to packages/Php/tests/Rector/BinaryOp/IsIterableRector/Fixture/polyfill_function.php.inc diff --git a/packages/Php/tests/Rector/BinaryOp/IsIterableRector/PolyfillRectorTest.php b/packages/Php/tests/Rector/BinaryOp/IsIterableRector/PolyfillRectorTest.php index c803d167834..25effe2945e 100644 --- a/packages/Php/tests/Rector/BinaryOp/IsIterableRector/PolyfillRectorTest.php +++ b/packages/Php/tests/Rector/BinaryOp/IsIterableRector/PolyfillRectorTest.php @@ -38,7 +38,7 @@ final class PolyfillRectorTest extends AbstractRectorTestCase public function test(): void { - $this->doTestFiles([__DIR__ . '/Fixture/polyfil_function.php.inc']); + $this->doTestFiles([__DIR__ . '/Fixture/polyfill_function.php.inc']); } public function getRectorClass(): string