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); |
|
|
|
|
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); |
|
|
|
|
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); |
|
|
|
|
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
|
|
|
|