48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Shared\Pagination;
|
||
|
|
|
||
|
|
use Shared\Pagination\PageNumber;
|
||
|
|
use Shared\Pagination\PageSize;
|
||
|
|
|
||
|
|
covers(PageSize::class);
|
||
|
|
|
||
|
|
it('creates page size with default, of, default factory, and max boundary', function (): void {
|
||
|
|
// GIVEN / WHEN
|
||
|
|
$defaultConstructed = new PageSize();
|
||
|
|
$ofFifty = PageSize::of(50);
|
||
|
|
$defaultFactory = PageSize::default();
|
||
|
|
$maxBoundary = PageSize::of(PageSize::MAX_PAGE_SIZE);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($defaultConstructed->value())->toBe(25)
|
||
|
|
->and($ofFifty->value())->toBe(50)
|
||
|
|
->and($defaultFactory->value())->toBe(25)
|
||
|
|
->and($maxBoundary->value())->toBe(10000)
|
||
|
|
->and((string) $ofFifty)->toBe('50')
|
||
|
|
->and(json_encode($ofFifty))->toBe('50');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('checks equality with same, different, and non-PageSize values', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$size = PageSize::of(25);
|
||
|
|
|
||
|
|
// WHEN / THEN
|
||
|
|
expect($size->equals(PageSize::of(25)))->toBeTrue()
|
||
|
|
->and($size->equals(PageSize::of(50)))->toBeFalse()
|
||
|
|
->and($size->equals(null))->toBeFalse()
|
||
|
|
->and($size->equals(new PageNumber(25)))->toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('rejects zero, negative, and above-max page sizes', function (int $invalidValue): void {
|
||
|
|
// GIVEN / WHEN / THEN
|
||
|
|
expect(static fn (): PageSize => new PageSize($invalidValue))
|
||
|
|
->toThrow(\InvalidArgumentException::class);
|
||
|
|
})->with([
|
||
|
|
'zero' => 0,
|
||
|
|
'negative' => -1,
|
||
|
|
'above max' => 10001,
|
||
|
|
]);
|