Completed
Pull Request — master (#8)
by Hugo
01:31
created

ResponseSpec::it_should_has_errors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace spec\Yproximite\Api;
4
5
use PhpSpec\ObjectBehavior;
6
use Yproximite\Api\Response;
7
8
class ResponseSpec extends ObjectBehavior
9
{
10
    public function it_is_initializable()
11
    {
12
        $this->shouldHaveType(Response::class);
13
    }
14
15
    public function it_should_be_valid()
16
    {
17
        $data = [
18
            'me' => [
19
                'firstName' => 'Hugo',
20
                'lastName'  => 'Alliaume',
21
            ],
22
        ];
23
24
        $this->beConstructedWith(['data' => $data]);
25
26
        $this->getData()->shouldBeLike((object) $data);
27
28
        $this->hasErrors()->shouldReturn(false);
29
        $this->getErrors()->shouldReturn([]);
30
31
        $this->hasWarnings()->shouldReturn(false);
32
        $this->getWarnings()->shouldReturn([]);
33
    }
34
35
    public function it_should_has_errors()
36
    {
37
        $errors = [
38
            [
39
                'message' => 'An error message.',
40
                'path'    => ['path', 'to', 'field'],
41
            ],
42
        ];
43
44
        $this->beConstructedWith([
45
            'data'   => null,
46
            'errors' => $errors,
47
        ]);
48
49
        $this->getData()->shouldReturn(null);
50
51
        $this->hasErrors()->shouldReturn(true);
52
        $this->getErrors()->shouldReturn($errors);
53
54
        $this->hasWarnings()->shouldReturn(false);
55
        $this->getWarnings()->shouldReturn([]);
56
    }
57
58
    public function it_should_has_warnings()
59
    {
60
        $data = [
61
            'foo' => [
62
                'bar'  => null,
63
                'site' => ['id' => 123],
64
            ],
65
        ];
66
67
        $warnings = [
68
            [
69
                'message' => 'Access denied to this field',
70
                'path'    => ['foo', 'bar'],
71
            ],
72
        ];
73
74
        $this->beConstructedWith([
75
            'data'       => $data,
76
            'extensions' => [
77
                'warnings' => $warnings,
78
            ],
79
        ]);
80
81
        $this->getData()->shouldBeLike((object) $data);
82
83
        $this->hasErrors()->shouldReturn(false);
84
        $this->getErrors()->shouldReturn([]);
85
86
        $this->hasWarnings()->shouldReturn(true);
87
        $this->getWarnings()->shouldReturn($warnings);
88
    }
89
}
90