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

OptionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace ArinaSystems\JsonResponse\Tests;
4
5
use ArinaSystems\JsonResponse\Option;
6
use Illuminate\Support\Facades\Config;
7
8
class OptionTest extends TestCase
9
{
10
    /**
11
     * @var \ArinaSystems\JsonResponse\Option
12
     */
13
    protected $options;
14
15
    /**
16
     * @var array
17
     */
18
    protected $config;
19
20
    /**
21
     * Setup the test environment.
22
     *
23
     * @return void
24
     */
25
    public function setUp(): void
26
    {
27
        parent::setUp();
28
29
        $this->config = Config::get('json-response');
30
        $this->options = new Option($this->config);
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function it_loads_the_given_config_array()
37
    {
38
        $this->assertEquals($this->options->all(), $this->config);
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function it_returns_a_value_of_given_key()
45
    {
46
        $this->assertEquals($this->options->get('attributes'), $this->config['attributes']);
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function it_returns_a_value_of_given_key_with_default_value()
53
    {
54
        $this->assertEquals($this->options->get('some_key', 'default'), 'default');
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function it_can_set_a_value_of_given_key()
61
    {
62
        $value = $this->options->set('some_key', 'some_value')->get('some_key');
63
        $this->assertEquals($value, 'some_value');
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_can_set_an_array_of_keys_and_values()
70
    {
71
        $value = $this->options->set([
72
            'some_key'         => 'some_value',
73
            'another_some_key' => 'another_some_value',
74
        ]);
75
76
        $this->assertEquals($value->get('some_key'), 'some_value');
77
        $this->assertEquals($value->get('another_some_key'), 'another_some_value');
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function it_can_set_a_value_of_given_key_with_magic_methods()
84
    {
85
        $this->options->some_key = 'some_value';
86
        $value = $this->options->get('some_key');
87
88
        $this->assertEquals($value, 'some_value');
89
    }
90
91
    /**
92
     * @test
93
     */
94
    public function it_can_get_value_of_given_key_with_magic_methods()
95
    {
96
        $this->assertEquals($this->options->attributes, $this->config['attributes']);
97
    }
98
}
99