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 316a4d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DoctrineObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,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
12 changes: 12 additions & 0 deletions tests/DoctrineObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2927,6 +2927,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 +2947,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 +2964,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 316a4d5

Please sign in to comment.