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

AssertJsonResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A seeJsonStructureEquals() 0 8 2
A jsonResponse() 0 6 2
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