Completed
Push — master ( 000800...90ac47 )
by Mathieu
09:18
created

AssertJsonResponse::jsonResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace LaravelFr\ApiTests;
4
5
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
6
7
trait AssertJsonResponse
8
{
9
    use AssertArrays, MakesHttpRequests;
10
11
    /**
12
     * Assert that the JSON response has exactly the given structure.
13
     *
14
     * @param  array $structure
15
     * @param  array|null $responseData
16
     *
17
     * @return $this
18
     */
19
    public function seeJsonStructureEquals(array $structure, $responseData = null)
20
    {
21
        if (!$responseData) {
22
            $responseData = $this->decodeResponseJson();
23
        }
24
25
        return $this->assertArrayStructureEquals($structure, $responseData);
26
    }
27
28
    /**
29
     * Return the json response or a part of it as an array.
30
     *
31
     * @param  string $key
32
     *
33
     * @return mixed
34
     */
35
    public function jsonResponse($key = null)
36
    {
37
        $response = $this->decodeResponseJson();
38
39
        return $key ? array_get($response, $key) : $response;
40
    }
41
}
42