Skip to content

Commit

Permalink
Revert "Add Support for Predefined Enum Collections in DataObject Ini…
Browse files Browse the repository at this point in the history
…tialization"
  • Loading branch information
rubenvanassche authored Jun 13, 2024
1 parent c5bcc48 commit 8ade75a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
2 changes: 1 addition & 1 deletion src/Casts/EnumCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 0 additions & 16 deletions tests/Casts/EnumCastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 8ade75a

Please sign in to comment.