Skip to content

Commit

Permalink
Data: add serialize support
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Jan 16, 2023
1 parent d7eaf2c commit 4512662
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ public function __toString()
}


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


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


/**
* @return array<string, mixed>
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/src/AresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function testFreelancer(): void
Assert::same('A', $aresData->psu(Ares\Data\SubjectFlag::RZP_4));
Assert::same('N', $aresData->psu(Ares\Data\SubjectFlag::NRPZS_5));
Assert::same('A', $aresData->psu(Ares\Data\SubjectFlag::RPDPH_6));

Assert::equal($aresData, unserialize(serialize($aresData)));
}


Expand Down

0 comments on commit 4512662

Please sign in to comment.