Completed
Push — 6.0 ( 96b69f...c11ada )
by liu
02:52
created

ConfigTest::testLoad()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
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
1 ignored issue
show
Coding Style introduced by
Missing doc comment for class ConfigTest
Loading history...
10
{
11
    public function testLoad()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testLoad()
Loading history...
12
    {
13
        $root = vfsStream::setup();
14
        $file = vfsStream::newFile('test.php')->setContent("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()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testSetAndGet()
Loading history...
28
    {
29
        $config = new Config();
30
31
        $config->set([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
32
            'key1' => 'value1',
33
            'key2' => [
34
                'key1' => 'value1-2',
35
            ],
36
        ], 'test');
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
37
38
        $this->assertTrue($config->has('test.key1'));
39
        $this->assertEquals('value1', $config->get('test.key1'));
40
        $this->assertEquals('value1-2', $config->get('test.key2.key1'));
41
42
        $this->assertEquals(['key1' => 'value3'], $config->get('test.key2'));
43
        $this->assertFalse($config->has('test.key3'));
44
        $this->assertEquals('none', $config->get('test.key3', 'none'));
45
    }
46
}
47