Skip to content

Commit

Permalink
Merge pull request #9 from PhantPHP/Fix-CollectionPaginatedTest
Browse files Browse the repository at this point in the history
Fix collection paginated test
  • Loading branch information
lennyrouanet authored Sep 8, 2022
2 parents 2c930f5 + ceda150 commit d495093
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions component/Abstract/CollectionPaginated.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Phant\DataStructure\Abstract;

use Phant\Error\NotCompliant;

abstract class CollectionPaginated extends Collection
{
private ?int $itemPage;
Expand Down Expand Up @@ -86,6 +88,16 @@ public function serialize(): ?array

public static function unserialize(array $serialized): self
{
if (!( array_key_exists('pagination', $serialized)
&& array_key_exists('page', $serialized['pagination'])
&& array_key_exists('current', $serialized['pagination']['page'])
&& array_key_exists('item', $serialized['pagination'])
&& array_key_exists('by_page', $serialized['pagination']['item'])
&& array_key_exists('total', $serialized['pagination']['item'])
)) {
throw new NotCompliant();
}

$collection = new static(
$serialized['pagination']['page']['current'],
$serialized['pagination']['item']['by_page'],
Expand Down
9 changes: 9 additions & 0 deletions test/Abstract/CollectionPaginatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Value,
};

use Phant\Error\NotCompliant;

final class CollectionPaginatedTest extends \PHPUnit\Framework\TestCase
{
public function testInterface(): void
Expand Down Expand Up @@ -83,4 +85,11 @@ public function testInterface(): void

$this->assertEquals($collection, $unserialized);
}

public function testUnserializeNotCompliant(): void
{
$this->expectException(NotCompliant::class);

CollectionPaginated::unserialize([[]]);
}
}

0 comments on commit d495093

Please sign in to comment.