45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Shared\Pagination;
|
||
|
|
|
||
|
|
use Shared\Pagination\PageNumber;
|
||
|
|
use Shared\Pagination\PageSize;
|
||
|
|
|
||
|
|
covers(PageNumber::class);
|
||
|
|
|
||
|
|
it('creates page number with default, of, and default factory', function (): void {
|
||
|
|
// GIVEN / WHEN
|
||
|
|
$defaultConstructed = new PageNumber();
|
||
|
|
$ofFive = PageNumber::of(5);
|
||
|
|
$defaultFactory = PageNumber::default();
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($defaultConstructed->value())->toBe(1)
|
||
|
|
->and($ofFive->value())->toBe(5)
|
||
|
|
->and($defaultFactory->value())->toBe(1)
|
||
|
|
->and((string) $ofFive)->toBe('5')
|
||
|
|
->and(json_encode($ofFive))->toBe('5');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('checks equality with same, different, and non-PageNumber values', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$page = PageNumber::of(3);
|
||
|
|
|
||
|
|
// WHEN / THEN
|
||
|
|
expect($page->equals(PageNumber::of(3)))->toBeTrue()
|
||
|
|
->and($page->equals(PageNumber::of(4)))->toBeFalse()
|
||
|
|
->and($page->equals(null))->toBeFalse()
|
||
|
|
->and($page->equals(new PageSize(1)))->toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('rejects zero and negative page numbers', function (int $invalidValue): void {
|
||
|
|
// GIVEN / WHEN / THEN
|
||
|
|
expect(static fn (): PageNumber => new PageNumber($invalidValue))
|
||
|
|
->toThrow(\InvalidArgumentException::class, 'Page number must be greater than 0');
|
||
|
|
})->with([
|
||
|
|
'zero' => 0,
|
||
|
|
'negative' => -3,
|
||
|
|
]);
|