summaryrefslogtreecommitdiff
path: root/tests/Unit/Config/ConfigTest.php
blob: 043599fdde171550e24d39fe872556c7f7bd4597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php

namespace Engelsystem\Test\Unit\Config;

use Engelsystem\Config\Config;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
    /**
     * @covers \Engelsystem\Config\Config::get
     */
    public function testGet()
    {
        $config = new Config();

        $config->set('test', 'FooBar');
        $this->assertEquals(['test' => 'FooBar'], $config->get(null));
        $this->assertEquals('FooBar', $config->get('test'));

        $this->assertEquals('defaultValue', $config->get('notExisting', 'defaultValue'));

        $this->assertNull($config->get('notExisting'));
    }

    /**
     * @covers \Engelsystem\Config\Config::set
     */
    public function testSet()
    {
        $config = new Config();

        $config->set('test', 'FooBar');
        $this->assertEquals('FooBar', $config->get('test'));

        $config->set([
            'name' => 'Engelsystem',
            'mail' => ['user' => 'test'],
        ]);
        $this->assertEquals('Engelsystem', $config->get('name'));
        $this->assertEquals(['user' => 'test'], $config->get('mail'));
    }

    /**
     * @covers \Engelsystem\Config\Config::has
     */
    public function testHas()
    {
        $config = new Config();

        $this->assertFalse($config->has('test'));

        $config->set('test', 'FooBar');
        $this->assertTrue($config->has('test'));
    }

    /**
     * @covers \Engelsystem\Config\Config::remove
     */
    public function testRemove()
    {
        $config = new Config();
        $config->set(['foo' => 'bar', 'test' => '123']);

        $config->remove('foo');
        $this->assertEquals(['test' => '123'], $config->get(null));
    }

    /**
     * @covers \Engelsystem\Config\Config::__get
     */
    public function testMagicGet()
    {
        $config = new Config();

        $config->set('test', 'FooBar');
        $this->assertEquals('FooBar', $config->test);
    }

    /**
     * @covers \Engelsystem\Config\Config::__set
     */
    public function testMagicSet()
    {
        $config = new Config();

        $config->test = 'FooBar';
        $this->assertEquals('FooBar', $config->get('test'));
    }

    /**
     * @covers \Engelsystem\Config\Config::__isset
     */
    public function testMagicIsset()
    {
        $config = new Config();

        $this->assertFalse(isset($config->test));

        $config->set('test', 'FooBar');
        $this->assertTrue(isset($config->test));
    }

    /**
     * @covers \Engelsystem\Config\Config::__unset
     */
    public function testMagicUnset()
    {
        $config = new Config();
        $config->set(['foo' => 'bar', 'test' => '123']);

        unset($config->foo);
        $this->assertEquals(['test' => '123'], $config->get(null));
    }
}