File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
tests/Domain/ValueObjects Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,11 @@ public function serialize(): ?string
187
187
return serialize ($ this ->value );
188
188
}
189
189
190
+ public function __serialize (): array
191
+ {
192
+ return $ this ->value ;
193
+ }
194
+
190
195
/**
191
196
* Constructs the object.
192
197
*
@@ -197,6 +202,11 @@ public function unserialize($serialized): void
197
202
$ this ->value = unserialize ($ serialized );
198
203
}
199
204
205
+ public function __unserialize (array $ data ): void
206
+ {
207
+ $ this ->value = $ data ;
208
+ }
209
+
200
210
/**
201
211
* Count elements of an object.
202
212
*
@@ -216,4 +226,4 @@ public function __toString(): string
216
226
{
217
227
return json_encode ($ this ->value );
218
228
}
219
- }
229
+ }
Original file line number Diff line number Diff line change @@ -63,4 +63,14 @@ public function testShouldIterateOverEachItem(): void
63
63
$ this ->assertIsString ($ item );
64
64
}
65
65
}
66
- }
66
+
67
+ public function testShouldBeSerializable (): void
68
+ {
69
+ $ vo = new ShoppingList (['Milk ' , 'Eggs ' , 'Yogurt ' ]);
70
+ $ unserialized = unserialize (serialize ($ vo ));
71
+
72
+ foreach ($ vo as $ item ) {
73
+ $ this ->assertContains ($ item , $ unserialized );
74
+ }
75
+ }
76
+ }
You can’t perform that action at this time.
0 commit comments