3
3
use Tests \Fixtures \Model ;
4
4
use Tests \Fixtures \ModelAttribute ;
5
5
6
- enum SerializerGlobalEnum {
7
- case Admin;
8
- case Guest;
9
- case Moderator;
10
- }
11
-
12
6
test ('enums ' , function () {
13
7
$ f = function (SerializerGlobalEnum $ role ) {
14
8
return $ role ;
@@ -57,11 +51,16 @@ enum SerializerScopedEnum {
57
51
expect ($ f ())->toBe (SerializerScopedEnum::Admin);
58
52
})->with ('serializers ' );
59
53
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 ' );
65
64
66
65
test ('backed enums ' , function () {
67
66
$ f = function (SerializerGlobalBackedEnum $ role ) {
@@ -112,6 +111,17 @@ enum SerializerScopedBackedEnum: string {
112
111
expect ($ f ())->toBe (SerializerScopedBackedEnum::Admin);
113
112
})->with ('serializers ' );
114
113
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
+
115
125
test ('array unpacking ' , function () {
116
126
$ f = function () {
117
127
$ array1 = ['a ' => 1 ];
@@ -394,15 +404,6 @@ enum SerializerScopedBackedEnum: string {
394
404
expect ($ f ())->toBeInstanceOf (SerializerPhp81Service::class);
395
405
})->with ('serializers ' );
396
406
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
-
406
407
interface SerializerPhp81HasId {}
407
408
interface SerializerPhp81HasName {}
408
409
@@ -477,6 +478,18 @@ public function getSelf(self $instance): self
477
478
}
478
479
}
479
480
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
+
480
493
#[Attribute(Attribute::TARGET_METHOD |Attribute::TARGET_FUNCTION )]
481
494
class MyAttribute
482
495
{
@@ -486,7 +499,7 @@ public function __construct(public $string, public $model)
486
499
}
487
500
}
488
501
489
- class ClassWithEnumField
502
+ class ClassWithEnumProperty
490
503
{
491
504
public SerializerGlobalEnum $ enum = SerializerGlobalEnum::Admin;
492
505
@@ -497,3 +510,15 @@ public function getClosure()
497
510
};
498
511
}
499
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