diff --git a/tests/Unit/Shared/PaginationTest.php b/tests/Unit/Shared/PaginationTest.php new file mode 100644 index 0000000..272ea4c --- /dev/null +++ b/tests/Unit/Shared/PaginationTest.php @@ -0,0 +1,61 @@ +from())->toBe(20) + ->and($pagination->to())->toBe(39) + ->and($pagination->pageSize())->toBe(20) + ->and($pagination->pageNumber())->toBe(2); + }); + + it('can be created from offset and limit', function (): void { + // GIVEN + $offset = 20; + $limit = 10; + + // WHEN + $pagination = Pagination::ofOffsetAndLimit($offset, $limit); + + // THEN + expect($pagination->from())->toBe(20) + ->and($pagination->to())->toBe(29) + ->and($pagination->pageSize())->toBe(10) + ->and($pagination->pageNumber())->toBe(3); + }); + + it('can be created using first page', function (): void { + // GIVEN + $pageSize = 15; + + // WHEN + $pagination = Pagination::firstPage($pageSize); + + // THEN + expect($pagination->from())->toBe(0) + ->and($pagination->to())->toBe(14) + ->and($pagination->pageSize())->toBe(15) + ->and($pagination->pageNumber())->toBe(1); + }); + + it('throws exception for invalid page size or negative index', function (): void { + // GIVEN / WHEN / THEN + expect(fn () => Pagination::ofPage(0, 10)) + ->toThrow(\InvalidArgumentException::class); + }); +});