Passed
Push — master ( abee1f...edc958 )
by Kirill
03:08
created

DefaultsTest::testGetNonExistedByDefaultConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Config;
13
14
class DefaultsTest extends BaseTest
15
{
16
    public function testGetNonExistedByDefaultConfig(): void
17
    {
18
        $cf = $this->getFactory();
19
        $cf->setDefaults('magic', ['key' => 'value']);
20
21
        $config = $cf->getConfig('magic');
22
23
        $this->assertEquals(
24
            ['key' => 'value'],
25
            $config
26
        );
27
28
        $this->assertSame($config, $cf->getConfig('magic'));
29
    }
30
31
    /**
32
     * @expectedException \Spiral\Core\Exception\ConfiguratorException
33
     */
34
    public function testDefaultsTwice(): void
35
    {
36
        $cf = $this->getFactory();
37
        $cf->setDefaults('magic', ['key' => 'value']);
38
        $cf->setDefaults('magic', ['key' => 'value']);
39
    }
40
41
    /**
42
     * @expectedException \Spiral\Core\Exception\ConfiguratorException
43
     */
44
    public function testDefaultToAlreadyLoaded(): void
45
    {
46
        $cf = $this->getFactory();
47
48
        $cf->getConfig('test');
49
        $cf->setDefaults('test', ['key' => 'value']);
50
    }
51
52
    public function testOverwrite(): void
53
    {
54
        $cf = $this->getFactory();
55
56
        $cf->setDefaults('test', [
57
            'key' => 'value'
58
        ]);
59
60
        $config = $cf->getConfig('test');
61
62
        $this->assertEquals(
63
            [
64
                'key'      => 'value',
65
                'id'       => 'hello world',
66
                'autowire' => new \Spiral\Core\Container\Autowire('something')
67
            ],
68
            $config
69
        );
70
71
        $this->assertSame($config, $cf->getConfig('test'));
72
    }
73
}
74