1
|
|
|
<?php |
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Deployer\Host; |
9
|
|
|
|
10
|
|
|
use Deployer\Configuration; |
11
|
|
|
use Deployer\Exception\ConfigurationException; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class ConfigurationTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testConfiguration() |
17
|
|
|
{ |
18
|
|
|
$config = new Configuration(); |
19
|
|
|
$config->set('int', 42); |
20
|
|
|
$config->set('string', 'value'); |
21
|
|
|
$config->set('array', [1, 'two']); |
22
|
|
|
$config->set('hyphen-ated', 'hyphen'); |
23
|
|
|
$config->set('parse', 'is {{int}}'); |
24
|
|
|
$config->set('parse-hyphen', 'has {{hyphen-ated}}'); |
25
|
|
|
$config->set('callback', function () { |
26
|
|
|
return 'callback'; |
27
|
|
|
}); |
28
|
|
|
$this->assertEquals(42, $config->get('int')); |
29
|
|
|
$this->assertEquals('value', $config->get('string')); |
30
|
|
|
$this->assertEquals([1, 'two'], $config->get('array')); |
31
|
|
|
$this->assertEquals('default', $config->get('no', 'default')); |
32
|
|
|
$this->assertEquals(null, $config->get('no', null)); |
33
|
|
|
$this->assertEquals('callback', $config->get('callback')); |
34
|
|
|
$this->assertEquals('is 42', $config->get('parse')); |
35
|
|
|
$this->assertEquals('has hyphen', $config->get('parse-hyphen')); |
36
|
|
|
|
37
|
|
|
$config->set('int', 11); |
38
|
|
|
$this->assertEquals('is 11', $config->get('parse')); |
39
|
|
|
|
40
|
|
|
$this->expectException('RuntimeException'); |
41
|
|
|
$config->get('so'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testAddParams() |
45
|
|
|
{ |
46
|
|
|
$config = new Configuration(); |
47
|
|
|
$config->set('config', [ |
48
|
|
|
'one', |
49
|
|
|
'two' => 2, |
50
|
|
|
'nested' => [], |
51
|
|
|
]); |
52
|
|
|
$config->add('config', [ |
53
|
|
|
'two' => 20, |
54
|
|
|
'nested' => [ |
55
|
|
|
'first', |
56
|
|
|
], |
57
|
|
|
]); |
58
|
|
|
$config->add('config', [ |
59
|
|
|
'nested' => [ |
60
|
|
|
'second', |
61
|
|
|
], |
62
|
|
|
]); |
63
|
|
|
$config->add('config', [ |
64
|
|
|
'extra', |
65
|
|
|
]); |
66
|
|
|
|
67
|
|
|
$expected = [ |
68
|
|
|
'one', |
69
|
|
|
'two' => 20, |
70
|
|
|
'nested' => [ |
71
|
|
|
'first', |
72
|
|
|
'second', |
73
|
|
|
], |
74
|
|
|
'extra', |
75
|
|
|
]; |
76
|
|
|
$this->assertEquals($expected, $config->get('config')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testAddParamsToNotArray() |
80
|
|
|
{ |
81
|
|
|
$this->expectException(ConfigurationException::class); |
82
|
|
|
|
83
|
|
|
$config = new Configuration(); |
84
|
|
|
$config->set('config', 'option'); |
85
|
|
|
$config->add('config', ['three']); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|