AssertsErrorFormat::assertErrorFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 3
dl 0
loc 20
rs 9.7998
c 2
b 0
f 0
1
<?php
2
3
namespace Digitonic\ApiTestSuite\Concerns;
4
5
use Illuminate\Support\Facades\View;
6
use Digitonic\ApiTestSuite\TestResponse;
7
8
trait AssertsErrorFormat
9
{
10
    /**
11
     * The template used allows regular expressions, e.g. in the default 400.blade.php template
12
     *
13
     * @param TestResponse $response
14
     * @param $status
15
     * @param array $data
16
     */
17
    protected function assertErrorFormat(TestResponse $response, $status, $data = [])
18
    {
19
        $response->assertStatus($status);
20
        $this->checkRequiredResponseHeaders($response);
0 ignored issues
show
Bug introduced by
It seems like checkRequiredResponseHeaders() 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

20
        $this->/** @scrutinizer ignore-call */ 
21
               checkRequiredResponseHeaders($response);
Loading history...
21
        $this->assertMatchesRegularExpression(
0 ignored issues
show
Bug introduced by
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

21
        $this->/** @scrutinizer ignore-call */ 
22
               assertMatchesRegularExpression(
Loading history...
22
            "/" . trim(
23
                View::file(
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facad...->exception))->render() can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

23
                /** @scrutinizer ignore-type */ View::file(
Loading history...
24
                    config('digitonic.api-test-suite.templates.base_path') . 'errors/' . $status . '.blade.php',
25
                    $data
26
                )->with(
27
28
                        ['exception' => $response->exception
0 ignored issues
show
Bug Best Practice introduced by
The property exception does not exist on Digitonic\ApiTestSuite\TestResponse. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
                    ]
30
                )->render()
31
32
) . "/",
33
            $response->getContent(),
0 ignored issues
show
Bug introduced by
The method getContent() does not exist on Digitonic\ApiTestSuite\TestResponse. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

33
            $response->/** @scrutinizer ignore-call */ 
34
                       getContent(),
Loading history...
34
35
            'Error response structure doesn\'t follow the template set up in '
36
            .config('digitonic.api-test-suite.templates.base_path').' errors/{errorStatusCode}.blade.php.'
37
        );
38
    }
39
}
40