Skip to content

Commit

Permalink
Make ArrayValue implementation compatible with the PHP8.1 and above (#41
Browse files Browse the repository at this point in the history
)
  • Loading branch information
segoddnja authored Jan 10, 2023
1 parent 46f9202 commit 6d2239c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Domain/ValueObjects/ArrayValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public function serialize(): ?string
return serialize($this->value);
}

public function __serialize(): array
{
return $this->value;
}

/**
* Constructs the object.
*
Expand All @@ -197,6 +202,11 @@ public function unserialize($serialized): void
$this->value = unserialize($serialized);
}

public function __unserialize(array $data): void
{
$this->value = $data;
}

/**
* Count elements of an object.
*
Expand All @@ -216,4 +226,4 @@ public function __toString(): string
{
return json_encode($this->value);
}
}
}
12 changes: 11 additions & 1 deletion tests/Domain/ValueObjects/ArrayValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ public function testShouldIterateOverEachItem(): void
$this->assertIsString($item);
}
}
}

public function testShouldBeSerializable(): void
{
$vo = new ShoppingList(['Milk', 'Eggs', 'Yogurt']);
$unserialized = unserialize(serialize($vo));

foreach ($vo as $item) {
$this->assertContains($item, $unserialized);
}
}
}

0 comments on commit 6d2239c

Please sign in to comment.