Skip to content

Commit

Permalink
Add check for PHP version for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyRatFans committed Apr 1, 2022
1 parent e1de222 commit 29b283e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/DoctrineObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use function get_class_methods;
use function gettype;
use function in_array;
use function interface_exists;
use function is_array;
use function is_callable;
use function is_int;
Expand Down Expand Up @@ -320,7 +319,7 @@ public function hydrateValue(string $name, $value, ?array $data = null)
return null;
}

if (interface_exists('BackedEnum') && $value instanceof BackedEnum) {
if (PHP_VERSION_ID >= 80100 && $value instanceof BackedEnum) {
return $value;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/DoctrineObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use function implode;
use function time;

use const PHP_VERSION_ID;

class DoctrineObjectTest extends TestCase
{
use ProphecyTrait;
Expand Down Expand Up @@ -2927,6 +2929,10 @@ public function testNestedHydrationByReference()

public function testHandleEnumConversionUsingByValue(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('PHP 8.1 required for enum compatibility');
}

// When using hydration by value, it will use the public API of the entity to set values (setters)
$entity = new Assets\SimpleEntityWithEnum();
$this->configureObjectManagerForSimpleEntityWithEnum();
Expand All @@ -2943,6 +2949,10 @@ public function testHandleEnumConversionUsingByValue(): void

public function testNullValueIsNotConvertedToEnum(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('PHP 8.1 required for enum compatibility');
}

$entity = new Assets\SimpleEntityWithEnum();
$this->configureObjectManagerForSimpleEntityWithEnum();

Expand All @@ -2956,6 +2966,10 @@ public function testNullValueIsNotConvertedToEnum(): void

public function testWrongEnumBackedValueThrowsException(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('PHP 8.1 required for enum compatibility');
}

$entity = new Assets\SimpleEntityWithEnum();
$this->configureObjectManagerForSimpleEntityWithEnum();

Expand Down

0 comments on commit 29b283e

Please sign in to comment.