forked from Respect/Config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLazyLoadTest.php
More file actions
56 lines (48 loc) · 1.78 KB
/
LazyLoadTest.php
File metadata and controls
56 lines (48 loc) · 1.78 KB
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
<?php
declare(strict_types=1);
namespace Respect\Config;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
#[CoversClass(Container::class)]
#[Group('issues')]
final class LazyLoadTest extends TestCase
{
public function testLazyLoadedParameters(): void
{
$config = "
my_string = 'Hey you!'
[hello Respect\Config\MyLazyLoadedHelloWorld]
string = [my_string]
";
$expected = 'Hello World!';
$container = new Container();
$container['my_string'] = $expected;
(new IniLoader($container))->fromString($config);
$this->assertEquals($expected, (string) $container->getItem('hello'));
}
public function testLazyLoadedInstance(): void
{
$config = "
my_string = 'Hey you!'
[hello Respect\Config\MyLazyLoadedHelloWorld]
string = [my_string]
[consumer Respect\Config\MyLazyLoadedHelloWorldConsumer]
hello = [hello]
";
$expected = 'Hello World!';
$container = new Container();
$container['my_string'] = $expected;
(new IniLoader($container))->fromString($config);
$this->assertEquals($expected, (string) $container->getItem('hello'));
$container = new Container();
$container['hello Respect\\Config\\MyLazyLoadedHelloWorld'] = ['string' => $expected];
(new IniLoader($container))->fromString($config);
$this->assertEquals($expected, (string) $container->getItem('hello'));
$container = new Container();
(new IniLoader($container))->fromString($config);
// __set detects existing Instantiator at 'hello' and calls setInstance()
$container->hello = new MyLazyLoadedHelloWorld($expected);
$this->assertEquals($expected, (string) $container->getItem('hello'));
}
}