getConstructor(); $constructor?->invoke($reflection->newInstanceWithoutConstructor()); // THEN expect(fn () => $reflection->newInstance()) ->toThrow(\ReflectionException::class); }); it('creates offset and limit pagination when offset or limit query param is present', function (): void { // GIVEN $request = HttpRequest::create('/api/v1/employees?offset=10&limit=50', 'GET'); // WHEN $pagination = RequestHelper::pagination($request, 25); // THEN expect($pagination)->toBeInstanceOf(Pagination::class) ->and($pagination->from())->toBe(10) ->and($pagination->to())->toBe(59); }); it('creates page and page size pagination using pageSize query param', function (): void { // GIVEN $request = HttpRequest::create('/api/v1/employees?page=2&pageSize=15', 'GET'); // WHEN $pagination = RequestHelper::pagination($request, 25); // THEN expect($pagination)->toBeInstanceOf(Pagination::class) ->and($pagination->from())->toBe(15) ->and($pagination->to())->toBe(29); }); it('creates page and page size pagination using per_page query param fallback', function (): void { // GIVEN $request = HttpRequest::create('/api/v1/employees?page=3&per_page=20', 'GET'); // WHEN $pagination = RequestHelper::pagination($request, 25); // THEN expect($pagination)->toBeInstanceOf(Pagination::class) ->and($pagination->from())->toBe(40) ->and($pagination->to())->toBe(59); }); it('creates page and page size pagination using pagination query param fallback', function (): void { // GIVEN $request = HttpRequest::create('/api/v1/employees?page=1&pagination=30', 'GET'); // WHEN $pagination = RequestHelper::pagination($request, 25); // THEN expect($pagination)->toBeInstanceOf(Pagination::class) ->and($pagination->from())->toBe(0) ->and($pagination->to())->toBe(29); }); it('uses default page size when no pagination parameters are supplied', function (): void { // GIVEN $request = HttpRequest::create('/api/v1/employees', 'GET'); // WHEN $pagination = RequestHelper::pagination($request, 25); // THEN expect($pagination)->toBeInstanceOf(Pagination::class) ->and($pagination->from())->toBe(0) ->and($pagination->to())->toBe(24); }); it('converts request URL to native RFC 3986 Uri instance', function (): void { // GIVEN $request = HttpRequest::create('http://localhost/api/v1/employees?foo=bar', 'GET'); // WHEN $uri = RequestHelper::toUri($request); // THEN expect($uri)->toBeInstanceOf(Uri::class) ->and($uri->toString())->toBe('http://localhost/api/v1/employees'); }); it('converts full request URL with query parameters to native RFC 3986 Uri instance', function (): void { // GIVEN $request = HttpRequest::create('http://localhost/api/v1/employees?page=2&pageSize=10', 'GET'); // WHEN $uri = RequestHelper::toFullUri($request); // THEN expect($uri)->toBeInstanceOf(Uri::class) ->and($uri->toString())->toBe('http://localhost/api/v1/employees?page=2&pageSize=10'); }); });