From 8ade75aeedd5e7667c213ccc5d308454466c6be6 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Thu, 13 Jun 2024 14:07:13 +0200 Subject: [PATCH] Revert "Add Support for Predefined Enum Collections in DataObject Initialization" --- src/Casts/EnumCast.php | 2 +- tests/Casts/EnumCastTest.php | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/Casts/EnumCast.php b/src/Casts/EnumCast.php index c0cc4b4a..fa3cde72 100644 --- a/src/Casts/EnumCast.php +++ b/src/Casts/EnumCast.php @@ -38,7 +38,7 @@ protected function castValue( /** @var class-string<\BackedEnum> $type */ try { - return $value instanceof $type && $value === $type::from($value->value) ? $value : $type::from($value); + return $type::from($value); } catch (Throwable $e) { throw CannotCastEnum::create($type, $value); } diff --git a/tests/Casts/EnumCastTest.php b/tests/Casts/EnumCastTest.php index cc54c79c..219fca57 100644 --- a/tests/Casts/EnumCastTest.php +++ b/tests/Casts/EnumCastTest.php @@ -71,19 +71,3 @@ ) ->toEqual(Uncastable::create()); }); - - -it('it can create data when enum is already casted', function () { - $class = new class () { - public DummyBackedEnum $enum; - }; - - expect( - $this->caster->cast( - FakeDataStructureFactory::property($class, 'enum'), - DummyBackedEnum::FOO, - [], - CreationContextFactory::createFromConfig($class::class)->get() - ) - )->toEqual(DummyBackedEnum::FOO); -});