Skip to content

Instantly share code, notes, and snippets.

@vamuigua
Forked from dillingham/Assert-Pagination.md
Created May 10, 2023 12:35
Show Gist options
  • Save vamuigua/535ae2db19e07fc02d4f67e176e60f80 to your computer and use it in GitHub Desktop.
Save vamuigua/535ae2db19e07fc02d4f67e176e60f80 to your computer and use it in GitHub Desktop.
Assert Laravel Pagination - Add helper to Testcase.php
public function assertHasPagination($response, $values = [])
{
    $response->assertJsonStructure([
        'links' => [
            'first',
            'last',
            'prev',
            'next',
        ]
    ]);

    $response->assertJsonStructure([
        'meta' => [
            'current_page',
            'from',
            'last_page',
            'path',
            'per_page',
            'to',
            'total',
        ]
    ]);

    if(count($values) == 0) return;

    foreach($values as $key => $value) {
        $response->assertJsonPath("meta.$key", $value);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment