Issues (56)

src/Concerns/AssertPagination.php (3 issues)

1
<?php
2
3
namespace Digitonic\ApiTestSuite\Concerns;
4
5
use Illuminate\Foundation\Testing\TestResponse;
6
use Illuminate\Http\Response;
7
use Illuminate\Support\Facades\View;
8
9
trait AssertPagination
10
{
11
    /**
12
     * @param $response
13
     * @param $expectedCount
14
     */
15
    protected function assertPaginationFormat(TestResponse $response, $expectedCount, $expectedTotal)
16
    {
17
        $response->assertStatus(Response::HTTP_OK);
18
        $this->assertCount(
0 ignored issues
show
It seems like assertCount() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $this->/** @scrutinizer ignore-call */ 
19
               assertCount(
Loading history...
19
            $expectedCount,
20
            json_decode($response->getContent(), true)['data'],
21
            'Pagination is failing. The number of entities returned doesn\'t match the expected '
22
            . $expectedCount
23
        );
24
        $this->assertPaginationResponseStructure($response, $expectedTotal);
25
    }
26
27
    /**
28
     * @param TestResponse $response
29
     * @param $total
30
     */
31
    protected function assertPaginationResponseStructure(TestResponse $response, $total)
32
    {
33
        $this->assertMatchesRegularExpression(
0 ignored issues
show
It seems like assertMatchesRegularExpression() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               assertMatchesRegularExpression(
Loading history...
34
            "/" . View::file(
0 ignored issues
show
Are you sure Illuminate\Support\Facad...' => $total))->render() of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
            "/" . /** @scrutinizer ignore-type */ View::file(
Loading history...
35
                config('digitonic.api-test-suite.templates.base_path') . 'pagination/pagination.blade.php',
36
                [
37
                    'total' => $total
38
                ]
39
            )->render() . "/",
40
            $response->getContent(),
41
            'Pagination response structure doesn\'t follow the template set up in '
42
            .config('digitonic.api-test-suite.templates.base_path').' pagination/pagination.blade.php.'
43
        );
44
    }
45
46
    /**
47
     * @return float
48
     */
49
    protected function entitiesNumber()
50
    {
51
        return 1.5 * $this->entitiesPerPage();
52
    }
53
54
    /**
55
     * @return int
56
     */
57
    protected function entitiesPerPage()
58
    {
59
        return config('digitonic.api-test-suite.entities_per_page');
60
    }
61
}
62