Skip to content

[pagination-plugin] How do I deal with a paginated API endpoint without knowing the "total" number of pages/items? And how to test it? #410

Discussion options

You must be logged in to vote

I found partial solutions to my problem and ended up doing something like this, which works, but may be a bit wonky. If this might help someone googling the question, I will post it anyway! Any improvements or best practices are welcome.

Working with a broken API endpoint

I returned $response->json('data') ?? [] in my getPageItems() as well as editing my request to parse an empty directory.

public function createDtoFromResponse(Response $response): mixed
{
    $data = $response->json()['data'] ?? [];

    return new DirectoryDTO(
        directory: $data,
    );
}

Testing paginated results

For the paginated tests, I was able to get the MockResponse in the correct order by parsing the Pend…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CeriseGoutPelican
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant