generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 259
Open
Description
✏️ Describe the bug
Issue with PropertyMorphableData Data class
The nullable enum type field (default: null) is always null inside morph() method eventhough property was correctly resolved.
DataMorphClassResolver is not handling this case in a proper way.
↪️ To Reproduce
it('can resolve morph class with backed enum type ignoring default value', function () {
abstract class TestAbstractMorphableDataWithNullableBackedEnum extends Data implements PropertyMorphableData
{
#[PropertyForMorph]
public ?DummyBackedEnum $type = null;
public static function morph(array $properties): ?string
{
return $properties['type']?->value;
}
};
$morph = app(DataMorphClassResolver::class)->execute(
app(DataConfig::class)->getDataClass(TestAbstractMorphableDataWithNullableBackedEnum::class),
[['type' => DummyBackedEnum::FOO]]
);
expect($morph)->toBe(DummyBackedEnum::FOO->value);
});Debuging \Spatie\LaravelData\Resolvers\DataMorphClassResolver::execute:
Resolved property value

✅ Expected behavior
The default value must not be applied in case the field was correctly resolved.
🖥️ Versions
Laravel: 12
Laravel Data: 4.18
PHP: 8.4.4
Metadata
Metadata
Assignees
Labels
No labels
