Completed
Branch 6.0 (d30585)
by yun
04:17
created

ConfigTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 21
c 3
b 0
f 0
dl 0
loc 36
rs 10
wmc 2
1
<?php
2
3
namespace think\tests;
4
5
use org\bovigo\vfs\vfsStream;
6
use PHPUnit\Framework\TestCase;
7
use think\Config;
8
9
class ConfigTest extends TestCase
10
{
11
    public function testLoad()
12
    {
13
        $root = vfsStream::setup();
14
        $file = vfsStream::newFile('test.php')->setContent("<?php return ['key1'=> 'value1','key2'=>'value2'];");
15
        $root->addChild($file);
16
17
        $config = new Config();
18
19
        $config->load($file->url(), 'test');
20
21
        $this->assertEquals('value1', $config->get('test.key1'));
22
        $this->assertEquals('value2', $config->get('test.key2'));
23
24
        $this->assertSame(['key1' => 'value1', 'key2' => 'value2'], $config->get('test'));
25
    }
26
27
    public function testSetAndGet()
28
    {
29
        $config = new Config();
30
31
        $config->set([
32
            'key1' => 'value1',
33
            'key2' => [
34
                'key3' => 'value3',
35
            ],
36
        ], 'test');
37
38
        $this->assertTrue($config->has('test.key1'));
39
        $this->assertEquals('value1', $config->get('test.key1'));
40
        $this->assertEquals('value3', $config->get('test.key2.key3'));
41
42
        $this->assertEquals(['key3' => 'value3'], $config->get('test.key2'));
43
        $this->assertFalse($config->has('test.key3'));
44
        $this->assertEquals('none', $config->get('test.key3', 'none'));
45
    }
46
}
47