Passed
Pull Request — master (#653)
by Aleksei
07:43
created

InjectionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 32
dl 0
loc 66
rs 10
c 0
b 0
f 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
use Spiral\Config\Exception\ConfigDeliveredException;
15
use Spiral\Config\Patch\Append;
16
use Spiral\Core\ConfigsInterface;
17
use Spiral\Core\Container\Autowire;
18
use Spiral\Core\InjectableConfig;
19
20
class InjectionTest extends BaseTest
21
{
22
    public function testInjection(): void
23
    {
24
        $cf = $this->getFactory();
25
        $this->container->bind(ConfigsInterface::class, $cf);
26
27
        $config = $this->container->get(TestConfig::class);
28
29
        $this->assertEquals(
30
            [
31
                'id'       => 'hello world',
32
                'autowire' => new Autowire('something'),
33
            ],
34
            $config->toArray()
35
        );
36
37
        $this->assertSame($config, $this->container->get(TestConfig::class));
38
    }
39
40
    public function testModifyAfterInjection(): void
41
    {
42
        $this->expectException(ConfigDeliveredException::class);
43
44
        $cf = $this->getFactory();
45
        $this->container->bind(ConfigsInterface::class, $cf);
46
47
        $config = $this->container->get(TestConfig::class);
48
49
        $this->assertEquals(
50
            [
51
                'id'       => 'hello world',
52
                'autowire' => new Autowire('something'),
53
            ],
54
            $config->toArray()
55
        );
56
57
        $cf->modify('test', new Append('.', null, 'value'));
58
    }
59
60
    public function testNonStrict(): void
61
    {
62
        $cf = $this->getFactory(null, false);
63
        $this->container->bind(ConfigsInterface::class, $cf);
64
65
        $config = $this->container->get(TestConfig::class);
66
67
        $this->assertEquals(
68
            [
69
                'id'       => 'hello world',
70
                'autowire' => new Autowire('something'),
71
            ],
72
            $config->toArray()
73
        );
74
75
        $cf->modify('test', new Append('.', 'key', 'value'));
76
77
        $config = $this->container->get(TestConfig::class);
78
79
        $this->assertEquals(
80
            [
81
                'id'       => 'hello world',
82
                'autowire' => new Autowire('something'),
83
                'key'      => 'value',
84
            ],
85
            $config->toArray()
86
        );
87
    }
88
}
89