Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Util/PhpCompatUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\MakerBundle\Util;

use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Component\HttpKernel\Kernel;

/**
* @author Jesse Rushlow <jr@rushlow.dev>
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make this method more specific. This is really about routing attributes. But soon we will probably start using Doctrine attributes and then other things. Possibly we could rename this to canUseRouteAttributes() and add other methods later.

}

protected function getPhpVersion(): string
Expand Down
10 changes: 10 additions & 0 deletions tests/Util/PhpVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jr@rushlow.dev>
Expand Down Expand Up @@ -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);
}

Expand Down