From 198da8a11c77e2c1859e4261069f825a3fa95115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 13 Aug 2026 11:50:16 +0200 Subject: [PATCH] test(Pagination): add unit tests for Pagination value object --- tests/Unit/Shared/PaginationTest.php | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/Unit/Shared/PaginationTest.php 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); + }); +});