Passed
Pull Request — master (#6)
by Arina
03:18
created

AttributeTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 93
rs 10
wmc 7
1
<?php
2
3
namespace ArinaSystems\JsonResponse\Tests;
4
5
use ArinaSystems\JsonResponse\Facades\Attribute;
6
7
class AttributeTest extends TestCase
8
{
9
    /**
10
     * @var \ArinaSystems\JsonResponse\Attribute
11
     */
12
    protected $attribute;
13
14
    /**
15
     * @var array
16
     */
17
    protected $attributes = [];
18
19
    /**
20
     * Setup the test environment.
21
     *
22
     * @return void
23
     */
24
    public function setUp(): void
25
    {
26
        parent::setUp();
27
28
        $this->attributes = [
29
            'success'   => true,
30
            'code'      => 2000,
31
            'http_code' => 200,
32
            'locale'    => 'en',
33
            'message'   => 'Hello, World!',
34
            'data'      => null,
35
            'headers'   => [],
36
            'exception' => null,
37
            'errors'    => [],
38
            'debug'     => null,
39
        ];
40
41
        $this->attribute = Attribute::set($this->attributes);
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function it_returns_value_of_given_key()
48
    {
49
        $this->assertEquals($this->attribute->get('code'), $this->attributes['code']);
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function it_returns_value_of_given_key_with_default_value()
56
    {
57
        $this->assertEquals($this->attribute->get('something', true), true);
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function it_can_set_a_value_of_given_key()
64
    {
65
        $value = $this->attribute->set('message', 'some_value')->get('message');
66
        $this->assertEquals($value, 'some_value');
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function it_can_set_an_array_of_keys_and_values()
73
    {
74
        $response = $this->attribute->set([
75
            'message' => 'some_value',
76
            'code'    => 5000,
77
        ]);
78
79
        $this->assertEquals($response->get('message'), 'some_value');
80
        $this->assertEquals($response->get('code'), 5000);
81
    }
82
83
    /**
84
     * @test
85
     */
86
    public function it_can_set_a_value_of_given_key_with_magic_methods()
87
    {
88
        $this->attribute->message = 'some_value';
89
        $value = $this->attribute->get('message');
90
91
        $this->assertEquals($value, 'some_value');
92
    }
93
94
    /**
95
     * @test
96
     */
97
    public function it_returns_value_of_given_key_with_magic_methods()
98
    {
99
        $this->assertEquals($this->attribute->code, $this->attributes['code']);
100
    }
101
}
102