Skip to content

Instantly share code, notes, and snippets.

@dillingham
Created February 22, 2020 20:24
Show Gist options
  • Save dillingham/fad0acc3ab40a3f0aa8f9584420498ab to your computer and use it in GitHub Desktop.
Save dillingham/fad0acc3ab40a3f0aa8f9584420498ab 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