@@ -22,6 +22,7 @@ protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
22
22
$ table ->increments ('id ' );
23
23
$ table ->string ('string_status ' , 100 )->nullable ();
24
24
$ table ->integer ('integer_status ' )->nullable ();
25
+ $ table ->string ('arrayable_status ' )->nullable ();
25
26
});
26
27
}
27
28
@@ -30,37 +31,47 @@ public function testEnumsAreCastable()
30
31
DB ::table ('enum_casts ' )->insert ([
31
32
'string_status ' => 'pending ' ,
32
33
'integer_status ' => 1 ,
34
+ 'arrayable_status ' => 'pending ' ,
33
35
]);
34
36
35
37
$ model = EloquentModelEnumCastingTestModel::first ();
36
38
37
39
$ this ->assertEquals (StringStatus::pending, $ model ->string_status );
38
40
$ this ->assertEquals (IntegerStatus::pending, $ model ->integer_status );
41
+ $ this ->assertEquals (ArrayableStatus::pending, $ model ->arrayable_status );
39
42
}
40
43
41
44
public function testEnumsReturnNullWhenNull ()
42
45
{
43
46
DB ::table ('enum_casts ' )->insert ([
44
47
'string_status ' => null ,
45
48
'integer_status ' => null ,
49
+ 'arrayable_status ' => null ,
46
50
]);
47
51
48
52
$ model = EloquentModelEnumCastingTestModel::first ();
49
53
50
54
$ this ->assertEquals (null , $ model ->string_status );
51
55
$ this ->assertEquals (null , $ model ->integer_status );
56
+ $ this ->assertEquals (null , $ model ->arrayable_status );
52
57
}
53
58
54
59
public function testEnumsAreCastableToArray ()
55
60
{
56
61
$ model = new EloquentModelEnumCastingTestModel ([
57
62
'string_status ' => StringStatus::pending,
58
63
'integer_status ' => IntegerStatus::pending,
64
+ 'arrayable_status ' => ArrayableStatus::pending,
59
65
]);
60
66
61
67
$ this ->assertEquals ([
62
68
'string_status ' => 'pending ' ,
63
69
'integer_status ' => 1 ,
70
+ 'arrayable_status ' => [
71
+ 'name ' => 'pending ' ,
72
+ 'value ' => 'pending ' ,
73
+ 'description ' => 'pending status description ' ,
74
+ ],
64
75
], $ model ->toArray ());
65
76
}
66
77
@@ -69,11 +80,13 @@ public function testEnumsAreCastableToArrayWhenNull()
69
80
$ model = new EloquentModelEnumCastingTestModel ([
70
81
'string_status ' => null ,
71
82
'integer_status ' => null ,
83
+ 'arrayable_status ' => null ,
72
84
]);
73
85
74
86
$ this ->assertEquals ([
75
87
'string_status ' => null ,
76
88
'integer_status ' => null ,
89
+ 'arrayable_status ' => null ,
77
90
], $ model ->toArray ());
78
91
}
79
92
@@ -82,6 +95,7 @@ public function testEnumsAreConvertedOnSave()
82
95
$ model = new EloquentModelEnumCastingTestModel ([
83
96
'string_status ' => StringStatus::pending,
84
97
'integer_status ' => IntegerStatus::pending,
98
+ 'arrayable_status ' => ArrayableStatus::pending,
85
99
]);
86
100
87
101
$ model ->save ();
@@ -90,6 +104,7 @@ public function testEnumsAreConvertedOnSave()
90
104
'id ' => $ model ->id ,
91
105
'string_status ' => 'pending ' ,
92
106
'integer_status ' => 1 ,
107
+ 'arrayable_status ' => 'pending ' ,
93
108
], DB ::table ('enum_casts ' )->where ('id ' , $ model ->id )->first ());
94
109
}
95
110
@@ -98,6 +113,7 @@ public function testEnumsAcceptNullOnSave()
98
113
$ model = new EloquentModelEnumCastingTestModel ([
99
114
'string_status ' => null ,
100
115
'integer_status ' => null ,
116
+ 'arrayable_status ' => null ,
101
117
]);
102
118
103
119
$ model ->save ();
@@ -106,6 +122,7 @@ public function testEnumsAcceptNullOnSave()
106
122
'id ' => $ model ->id ,
107
123
'string_status ' => null ,
108
124
'integer_status ' => null ,
125
+ 'arrayable_status ' => null ,
109
126
], DB ::table ('enum_casts ' )->where ('id ' , $ model ->id )->first ());
110
127
}
111
128
@@ -114,6 +131,7 @@ public function testEnumsAcceptBackedValueOnSave()
114
131
$ model = new EloquentModelEnumCastingTestModel ([
115
132
'string_status ' => 'pending ' ,
116
133
'integer_status ' => 1 ,
134
+ 'arrayable_status ' => 'pending ' ,
117
135
]);
118
136
119
137
$ model ->save ();
@@ -122,13 +140,15 @@ public function testEnumsAcceptBackedValueOnSave()
122
140
123
141
$ this ->assertEquals (StringStatus::pending, $ model ->string_status );
124
142
$ this ->assertEquals (IntegerStatus::pending, $ model ->integer_status );
143
+ $ this ->assertEquals (ArrayableStatus::pending, $ model ->arrayable_status );
125
144
}
126
145
127
146
public function testFirstOrNew ()
128
147
{
129
148
DB ::table ('enum_casts ' )->insert ([
130
149
'string_status ' => 'pending ' ,
131
150
'integer_status ' => 1 ,
151
+ 'arrayable_status ' => 'pending ' ,
132
152
]);
133
153
134
154
$ model = EloquentModelEnumCastingTestModel::firstOrNew ([
@@ -176,5 +196,6 @@ class EloquentModelEnumCastingTestModel extends Model
176
196
public $ casts = [
177
197
'string_status ' => StringStatus::class,
178
198
'integer_status ' => IntegerStatus::class,
199
+ 'arrayable_status ' => ArrayableStatus::class,
179
200
];
180
201
}
0 commit comments