diff --git a/src/Util/PhpCompatUtil.php b/src/Util/PhpCompatUtil.php index bd221839a..44c612119 100644 --- a/src/Util/PhpCompatUtil.php +++ b/src/Util/PhpCompatUtil.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\MakerBundle\Util; use Symfony\Bundle\MakerBundle\FileManager; +use Symfony\Component\HttpKernel\Kernel; /** * @author Jesse Rushlow @@ -32,7 +33,7 @@ public function canUseAttributes(): bool { $version = $this->getPhpVersion(); - return version_compare($version, '8alpha', '>='); + return version_compare($version, '8alpha', '>=') && Kernel::VERSION_ID >= 50200; } protected function getPhpVersion(): string diff --git a/tests/Util/PhpVersionTest.php b/tests/Util/PhpVersionTest.php index 84756cf4f..ac2ca4e0c 100644 --- a/tests/Util/PhpVersionTest.php +++ b/tests/Util/PhpVersionTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bundle\MakerBundle\FileManager; use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil; +use Symfony\Component\HttpKernel\Kernel; /** * @author Jesse Rushlow @@ -52,6 +53,15 @@ public function testUsesPhpPlatformFromComposerJsonFile(string $version, bool $e $result = $version->canUseAttributes(); + /* + * Symfony 5.2 is required to compare the result. Otherwise it will always + * return false regardless of the PHP Version. If the test suite is run w/ + * Symfony < 5.2, we assert false here but still rely on the assertions above. + */ + if (Kernel::VERSION_ID < 50200) { + $expectedResult = false; + } + self::assertSame($expectedResult, $result); }