Skip to content

Commit b70c4d2

Browse files
committed
Adds support for closure inside context with enum property
1 parent 3cdb166 commit b70c4d2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Serializers/Native.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static function wrapClosures(&$data, $storage)
242242
}
243243

244244
unset($value);
245-
} elseif (is_object($data) && ! $data instanceof static) {
245+
} elseif (is_object($data) && ! $data instanceof static && ! $data instanceof UnitEnum) {
246246
if (isset($storage[$data])) {
247247
$data = $storage[$data];
248248

tests/SerializerPhp81Test.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ enum SerializerScopedBackedEnum: string {
394394
expect($f())->toBeInstanceOf(SerializerPhp81Service::class);
395395
})->with('serializers');
396396

397+
test('closure defined inside class with enum property', function () {
398+
$object = new ClassWithEnumField();
399+
$f = $object->getClosure();
400+
401+
$f = s($f);
402+
403+
expect($f()->name)->toBe('Admin');
404+
})->with('serializers');
405+
397406
interface SerializerPhp81HasId {}
398407
interface SerializerPhp81HasName {}
399408

@@ -477,3 +486,14 @@ public function __construct(public $string, public $model)
477486
}
478487
}
479488

489+
class ClassWithEnumField
490+
{
491+
public SerializerGlobalEnum $enum = SerializerGlobalEnum::Admin;
492+
493+
public function getClosure()
494+
{
495+
return function () {
496+
return $this->enum;
497+
};
498+
}
499+
}

0 commit comments

Comments
 (0)