33use Tests \Fixtures \Model ;
44use Tests \Fixtures \ModelAttribute ;
55
6- enum SerializerGlobalEnum {
7- case Admin;
8- case Guest;
9- case Moderator;
10- }
11-
126test ('enums ' , function () {
137 $ f = function (SerializerGlobalEnum $ role ) {
148 return $ role ;
@@ -57,11 +51,16 @@ enum SerializerScopedEnum {
5751 expect ($ f ())->toBe (SerializerScopedEnum::Admin);
5852})->with ('serializers ' );
5953
60- enum SerializerGlobalBackedEnum: string {
61- case Admin = 'Administrator ' ;
62- case Guest = 'Guest ' ;
63- case Moderator = 'Moderator ' ;
64- }
54+ test ('enums properties ' , function () {
55+ $ object = new ClassWithEnumProperty ();
56+ $ f = $ object ->getClosure ();
57+
58+ $ f = s ($ f );
59+
60+ expect ($ f ())
61+ ->name ->toBe ('Admin ' )
62+ ->value ->toBeNull ();
63+ })->with ('serializers ' );
6564
6665test ('backed enums ' , function () {
6766 $ f = function (SerializerGlobalBackedEnum $ role ) {
@@ -112,6 +111,17 @@ enum SerializerScopedBackedEnum: string {
112111 expect ($ f ())->toBe (SerializerScopedBackedEnum::Admin);
113112})->with ('serializers ' );
114113
114+ test ('backed enums properties ' , function () {
115+ $ object = new ClassWithBackedEnumProperty ();
116+ $ f = $ object ->getClosure ();
117+
118+ $ f = s ($ f );
119+
120+ expect ($ f ())
121+ ->name ->toBe ('Admin ' )
122+ ->value ->toBe ('Administrator ' );
123+ })->with ('serializers ' );
124+
115125test ('array unpacking ' , function () {
116126 $ f = function () {
117127 $ array1 = ['a ' => 1 ];
@@ -468,6 +478,18 @@ public function getSelf(self $instance): self
468478 }
469479}
470480
481+ enum SerializerGlobalEnum {
482+ case Admin;
483+ case Guest;
484+ case Moderator;
485+ }
486+
487+ enum SerializerGlobalBackedEnum: string {
488+ case Admin = 'Administrator ' ;
489+ case Guest = 'Guest ' ;
490+ case Moderator = 'Moderator ' ;
491+ }
492+
471493#[Attribute(Attribute::TARGET_METHOD |Attribute::TARGET_FUNCTION )]
472494class MyAttribute
473495{
@@ -477,3 +499,26 @@ public function __construct(public $string, public $model)
477499 }
478500}
479501
502+ class ClassWithEnumProperty
503+ {
504+ public SerializerGlobalEnum $ enum = SerializerGlobalEnum::Admin;
505+
506+ public function getClosure ()
507+ {
508+ return function () {
509+ return $ this ->enum ;
510+ };
511+ }
512+ }
513+
514+ class ClassWithBackedEnumProperty
515+ {
516+ public SerializerGlobalBackedEnum $ enum = SerializerGlobalBackedEnum::Admin;
517+
518+ public function getClosure ()
519+ {
520+ return function () {
521+ return $ this ->enum ;
522+ };
523+ }
524+ }
0 commit comments