TestResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 32
rs 10
c 2
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A responseContent() 0 11 2
A assertStatus() 0 11 1
1
<?php
2
3
namespace Digitonic\ApiTestSuite;
4
use Illuminate\Foundation\Testing\Assert as PHPUnit;
5
6
class TestResponse extends \Illuminate\Foundation\Testing\TestResponse
7
{
8
    /**
9
     * Assert that the response has the given status code.
10
     *
11
     * @param  int  $status
12
     * @return $this
13
     */
14
    public function assertStatus($status)
15
    {
16
        $actual = $this->getStatusCode();
0 ignored issues
show
Bug introduced by
The method getStatusCode() 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

16
        /** @scrutinizer ignore-call */ 
17
        $actual = $this->getStatusCode();
Loading history...
17
18
        PHPUnit::assertTrue(
19
            $actual === $status,
20
            "Expected status code {$status} but received {$actual}. Response content: \n".
21
            print_r($this->responseContent(), true)
22
        );
23
24
        return $this;
25
    }
26
27
    public function responseContent()
28
    {
29
        $content = $this->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

29
        /** @scrutinizer ignore-call */ 
30
        $content = $this->getContent();
Loading history...
30
31
        $json = json_decode($content);
32
33
        if (json_last_error() === JSON_ERROR_NONE) {
34
            $content = $json;
35
        }
36
37
        return $content;
38
    }
39
}
40