Completed
Pull Request — 5.1 (#1327)
by
unknown
05:23
created

configTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 69
dl 0
loc 126
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testRange() 0 10 1
A testSet() 0 25 1
A testReset() 0 23 1
A testGet() 0 23 1
A testLoad() 0 9 1
A testHas() 0 17 1
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
12
/**
13
 * 配置测试
14
 * @author    Haotong Lin <[email protected]>
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 4
Loading history...
15
 */
16
17
namespace tests\thinkphp\library\think;
18
19
use tests\thinkphp\library\think\config\ConfigInitTrait;
20
use think\Config;
0 ignored issues
show
Bug introduced by
The type think\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
class configTest extends \PHPUnit_Framework_TestCase
1 ignored issue
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Coding Style introduced by
Missing class doc comment
Loading history...
Coding Style introduced by
Class name must begin with a capital letter
Loading history...
23
{
24
    use ConfigInitTrait;
25
26
    public function testRange()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
27
    {
28
        // test default range
29
        $this->assertEquals('_sys_', call_user_func(self::$internalRangeFoo));
30
31
        $this->assertTrue(is_array(call_user_func(self::$internalConfigFoo)));
32
        // test range initialization
33
        Config::range('_test_');
34
        $this->assertEquals('_test_', call_user_func(self::$internalRangeFoo));
35
        $this->assertEquals([], call_user_func(self::$internalConfigFoo)['_test_']);
36
    }
37
38
    // public function testParse()
39
    // {
40
    //  see \think\config\driver\...Test.php
41
    // }
42
43
    public function testLoad()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
44
    {
45
        $file   = APP_PATH . 'config' . EXT;
0 ignored issues
show
Bug introduced by
The constant tests\thinkphp\library\think\APP_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant tests\thinkphp\library\think\EXT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
46
        $config = array_change_key_case(include $file);
47
        $name   = '_name_';
48
        $range  = '_test_';
49
50
        $this->assertEquals($config, Config::load($file, $name, $range));
51
        $this->assertNotEquals(null, Config::load($file, $name, $range));
52
    }
53
54
    public function testHas()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
55
    {
56
        $range = '_test_';
57
        $this->assertFalse(Config::has('abcd', $range));
58
59
        call_user_func(self::$internalConfigFoo, [
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...
60
            $range => ['abcd' => 'value'],
61
        ]);
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...
62
        $this->assertTrue(Config::has('abcd', $range));
63
64
        // else ...
65
        $this->assertFalse(Config::has('abcd.efg', $range));
66
67
        call_user_func(self::$internalConfigFoo, [
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...
68
            $range => ['abcd' => ['efg' => 'value']],
69
        ]);
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...
70
        $this->assertTrue(Config::has('abcd.efg', $range));
71
    }
72
73
    public function testGet()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
74
    {
75
        $range = '_test_';
76
        call_user_func(self::$internalConfigFoo, [
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...
77
            $range => []
78
        ]);
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...
79
        $this->assertEquals([], Config::get(null, $range));
80
        $this->assertEquals(null, Config::get(null, 'does_not_exist'));
81
        $value = 'value';
82
        // test getting configuration
83
        call_user_func(self::$internalConfigFoo, [
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...
84
            $range => ['abcd' => 'efg']
85
        ]);
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...
86
        $this->assertEquals('efg', Config::get('abcd', $range));
87
        $this->assertEquals(null, Config::get('does_not_exist', $range));
88
        $this->assertEquals(null, Config::get('abcd', 'does_not_exist'));
89
        // test getting configuration with dot syntax
90
        call_user_func(self::$internalConfigFoo, [
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...
91
            $range => ['one' => ['two' => $value]]
92
        ]);
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...
93
        $this->assertEquals($value, Config::get('one.two', $range));
94
        $this->assertEquals(null, Config::get('one.does_not_exist', $range));
95
        $this->assertEquals(null, Config::get('one.two', 'does_not_exist'));
96
    }
97
98
    public function testSet()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
99
    {
100
        $range = '_test_';
101
102
        // without dot syntax
103
        $name  = 'name';
104
        $value = 'value';
105
        Config::set($name, $value, $range);
106
        $config = call_user_func(self::$internalConfigFoo);
107
        $this->assertEquals($value, $config[$range][$name]);
108
        // with dot syntax
109
        $name  = 'one.two';
110
        $value = 'dot value';
111
        Config::set($name, $value, $range);
112
        $config = call_user_func(self::$internalConfigFoo);
113
        $this->assertEquals($value, $config[$range]['one']['two']);
114
        // if (is_array($name)):
115
        // see testLoad()
116
        // ...
117
        // test getting all configurations...?
118
        // return self::$config[$range]; ??
119
        $value = ['all' => 'configuration'];
120
        call_user_func(self::$internalConfigFoo, [$range => $value]);
121
        $this->assertEquals($value, Config::set(null, null, $range));
122
        $this->assertNotEquals(null, Config::set(null, null, $range));
123
    }
124
125
    public function testReset()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
126
    {
127
        $range = '_test_';
128
        call_user_func(self::$internalConfigFoo, [$range => ['abcd' => 'efg']]);
129
130
        // clear all configurations
131
        Config::reset(true);
132
        $config = call_user_func(self::$internalConfigFoo);
133
        $this->assertEquals([], $config);
134
        // clear the configuration in range of parameter.
135
        call_user_func(self::$internalConfigFoo, [
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...
136
            $range => [
137
                'abcd' => 'efg',
138
                'hijk' => 'lmn',
139
            ],
140
            'a'    => 'b',
141
        ]);
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...
142
        Config::reset($range);
143
        $config = call_user_func(self::$internalConfigFoo);
144
        $this->assertEquals([
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...
145
            $range => [],
146
            'a'    => 'b',
147
        ], $config);
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...
148
    }
149
}
150