Completed
Pull Request — master (#9)
by Hugo
01:44
created

ResponseSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 5 1
A it_should_be_valid() 0 19 1
A it_should_has_errors() 0 22 1
B it_should_has_warnings() 0 31 1
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->beConstructedWith([]);
13
        $this->shouldHaveType(Response::class);
14
    }
15
16
    public function it_should_be_valid()
17
    {
18
        $data = [
19
            'me' => [
20
                'firstName' => 'Hugo',
21
                'lastName'  => 'Alliaume',
22
            ],
23
        ];
24
25
        $this->beConstructedWith(['data' => $data]);
26
27
        $this->getData()->shouldBeLike((object) $data);
28
29
        $this->hasErrors()->shouldReturn(false);
30
        $this->getErrors()->shouldReturn([]);
31
32
        $this->hasWarnings()->shouldReturn(false);
33
        $this->getWarnings()->shouldReturn([]);
34
    }
35
36
    public function it_should_has_errors()
37
    {
38
        $errors = [
39
            [
40
                'message' => 'An error message.',
41
                'path'    => ['path', 'to', 'field'],
42
            ],
43
        ];
44
45
        $this->beConstructedWith([
46
            'data'   => null,
47
            'errors' => $errors,
48
        ]);
49
50
        $this->getData()->shouldReturn(null);
51
52
        $this->hasErrors()->shouldReturn(true);
53
        $this->getErrors()->shouldReturn($errors);
54
55
        $this->hasWarnings()->shouldReturn(false);
56
        $this->getWarnings()->shouldReturn([]);
57
    }
58
59
    public function it_should_has_warnings()
60
    {
61
        $data = [
62
            'foo' => [
63
                'bar'  => null,
64
                'site' => ['id' => 123],
65
            ],
66
        ];
67
68
        $warnings = [
69
            [
70
                'message' => 'Access denied to this field',
71
                'path'    => ['foo', 'bar'],
72
            ],
73
        ];
74
75
        $this->beConstructedWith([
76
            'data'       => $data,
77
            'extensions' => [
78
                'warnings' => $warnings,
79
            ],
80
        ]);
81
82
        $this->getData()->shouldBeLike((object) $data);
83
84
        $this->hasErrors()->shouldReturn(false);
85
        $this->getErrors()->shouldReturn([]);
86
87
        $this->hasWarnings()->shouldReturn(true);
88
        $this->getWarnings()->shouldReturn($warnings);
89
    }
90
}
91