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
187187 return serialize ($ this ->value );
188188 }
189189
190+ public function __serialize (): array
191+ {
192+ return $ this ->value ;
193+ }
194+
190195 /**
191196 * Constructs the object.
192197 *
@@ -197,6 +202,11 @@ public function unserialize($serialized): void
197202 $ this ->value = unserialize ($ serialized );
198203 }
199204
205+ public function __unserialize (array $ data ): void
206+ {
207+ $ this ->value = $ data ;
208+ }
209+
200210 /**
201211 * Count elements of an object.
202212 *
@@ -216,4 +226,4 @@ public function __toString(): string
216226 {
217227 return json_encode ($ this ->value );
218228 }
219- }
229+ }
Original file line number Diff line number Diff line change @@ -63,4 +63,14 @@ public function testShouldIterateOverEachItem(): void
6363 $ this ->assertIsString ($ item );
6464 }
6565 }
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