Skip to content

Commit 6d2239c

Browse files
authored
Make ArrayValue implementation compatible with the PHP8.1 and above (#41)
1 parent 46f9202 commit 6d2239c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Domain/ValueObjects/ArrayValue.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
}

tests/Domain/ValueObjects/ArrayValueTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)