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

InjectionTest::testModifyAfterInjection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
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
use Spiral\Config\Patch\Append;
15
use Spiral\Core\ConfigsInterface;
16
use Spiral\Core\InjectableConfig;
17
18
class InjectionTest extends BaseTest
19
{
20
    public function testInjection(): void
21
    {
22
        $cf = $this->getFactory();
23
        $this->container->bind(ConfigsInterface::class, $cf);
0 ignored issues
show
Bug introduced by
$cf of type Spiral\Config\ConfigManager is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $this->container->bind(ConfigsInterface::class, /** @scrutinizer ignore-type */ $cf);
Loading history...
24
25
        $config = $this->container->get(TestConfig::class);
26
27
        $this->assertEquals(
28
            [
29
                'id'       => 'hello world',
30
                'autowire' => new \Spiral\Core\Container\Autowire('something')
31
            ],
32
            $config->toArray()
33
        );
34
35
        $this->assertSame($config, $this->container->get(TestConfig::class));
36
    }
37
38
    /**
39
     * @expectedException \Spiral\Config\Exception\ConfigDeliveredException
40
     */
41
    public function testModifyAfterInjection(): void
42
    {
43
        $cf = $this->getFactory();
44
        $this->container->bind(ConfigsInterface::class, $cf);
0 ignored issues
show
Bug introduced by
$cf of type Spiral\Config\ConfigManager is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $this->container->bind(ConfigsInterface::class, /** @scrutinizer ignore-type */ $cf);
Loading history...
45
46
        $config = $this->container->get(TestConfig::class);
47
48
        $this->assertEquals(
49
            [
50
                'id'       => 'hello world',
51
                'autowire' => new \Spiral\Core\Container\Autowire('something')
52
            ],
53
            $config->toArray()
54
        );
55
56
        $cf->modify('test', new Append('.', null, 'value'));
57
    }
58
59
    public function testNonStrict(): void
60
    {
61
        $cf = $this->getFactory(null, false);
62
        $this->container->bind(ConfigsInterface::class, $cf);
0 ignored issues
show
Bug introduced by
$cf of type Spiral\Config\ConfigManager is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        $this->container->bind(ConfigsInterface::class, /** @scrutinizer ignore-type */ $cf);
Loading history...
63
64
        $config = $this->container->get(TestConfig::class);
65
66
        $this->assertEquals(
67
            [
68
                'id'       => 'hello world',
69
                'autowire' => new \Spiral\Core\Container\Autowire('something')
70
            ],
71
            $config->toArray()
72
        );
73
74
        $cf->modify('test', new Append('.', 'key', 'value'));
75
76
        $config = $this->container->get(TestConfig::class);
77
78
        $this->assertEquals(
79
            [
80
                'id'       => 'hello world',
81
                'autowire' => new \Spiral\Core\Container\Autowire('something'),
82
                'key'      => 'value'
83
            ],
84
            $config->toArray()
85
        );
86
    }
87
}
88