Skip to content

Commit

Permalink
Merge pull request #790 from spatie/revert-776-main
Browse files Browse the repository at this point in the history
Revert "Add Support for Predefined Enum Collections in DataObject Initialization"
  • Loading branch information
rubenvanassche authored Jun 13, 2024
2 parents c5bcc48 + 8ade75a commit 92af136
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 92af136

Please sign in to comment.