46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Shared\Pagination;
|
|
|
|
use Shared\Pagination\PageOf;
|
|
use Shared\Pagination\Pagination;
|
|
|
|
covers(PageOf::class);
|
|
|
|
it('exposes pagination, total, and items', function (): void {
|
|
// GIVEN
|
|
$pagination = Pagination::firstPage();
|
|
$item1 = (object) ['id' => 1];
|
|
$item2 = (object) ['id' => 2];
|
|
$pageOf = new PageOf($pagination, [$item1, $item2], 42);
|
|
|
|
// WHEN
|
|
$returnedPagination = $pageOf->getPagination();
|
|
$returnedTotal = $pageOf->getTotal();
|
|
$returnedItems = $pageOf->getItems();
|
|
|
|
// THEN
|
|
expect($returnedPagination)->toBe($pagination)
|
|
->and($returnedTotal)->toBe(42)
|
|
->and($returnedItems)->toHaveCount(2)
|
|
->and($returnedItems[0]->id)->toBe(1)
|
|
->and($returnedItems[1]->id)->toBe(2);
|
|
});
|
|
|
|
it('returns cloned items so mutating returned objects does not affect internal state', function (): void {
|
|
// GIVEN
|
|
$pagination = Pagination::firstPage();
|
|
$item = new \stdClass();
|
|
$item->name = 'original';
|
|
$pageOf = new PageOf($pagination, [$item], 1);
|
|
|
|
// WHEN
|
|
$firstItems = $pageOf->getItems();
|
|
$firstItems[0]->name = 'mutated';
|
|
$secondItems = $pageOf->getItems();
|
|
|
|
// THEN
|
|
expect($secondItems[0]->name)->toBe('original');
|
|
});
|