1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Tests; |
3
|
|
|
|
4
|
|
|
use org\bovigo\vfs\vfsStream as Stream; |
5
|
|
|
use org\bovigo\vfs\vfsStreamFile as StreamFile; |
6
|
|
|
use org\bovigo\vfs\vfsStreamWrapper as StreamWrapper; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ConfigTest |
10
|
|
|
* |
11
|
|
|
* @since 2.2.0 |
12
|
|
|
* |
13
|
|
|
* @package Redaxscript |
14
|
|
|
* @category Tests |
15
|
|
|
* @author Henry Ruhs |
16
|
|
|
* |
17
|
|
|
* @covers Redaxscript\Config |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class ConfigTest extends TestCaseAbstract |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* array to restore config |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
protected $_configArray = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* setUp |
32
|
|
|
* |
33
|
|
|
* @since 3.0.0 |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
public function setUp() : void |
37
|
|
|
{ |
38
|
|
|
parent::setUp(); |
39
|
|
|
Stream::setup('root'); |
40
|
|
|
$file = new StreamFile('config.php'); |
41
|
|
|
StreamWrapper::getRoot()->addChild($file); |
42
|
|
|
$this->_configArray = $this->_config->getArray(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* tearDown |
47
|
|
|
* |
48
|
|
|
* @since 3.1.0 |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
public function tearDown() : void |
52
|
|
|
{ |
53
|
|
|
$this->_config->set('dbType', $this->_configArray['dbType']); |
54
|
|
|
$this->_config->set('dbHost', $this->_configArray['dbHost']); |
55
|
|
|
$this->_config->set('dbPrefix', $this->_configArray['dbPrefix']); |
56
|
|
|
$this->_config->set('dbName', $this->_configArray['dbName']); |
57
|
|
|
$this->_config->set('dbUser', $this->_configArray['dbUser']); |
58
|
|
|
$this->_config->set('dbPassword', $this->_configArray['dbPassword']); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* testInit |
63
|
|
|
* |
64
|
|
|
* @since 2.4.0 |
65
|
|
|
*/ |
66
|
|
|
|
67
|
|
|
public function testInit() : void |
68
|
|
|
{ |
69
|
|
|
/* setup */ |
70
|
|
|
|
71
|
|
|
$this->_config->init('config.php'); |
72
|
|
|
|
73
|
|
|
/* actual */ |
74
|
|
|
|
75
|
|
|
$actualArray = $this->_config->getArray(); |
76
|
|
|
|
77
|
|
|
/* compare */ |
78
|
|
|
|
79
|
|
|
$this->assertArrayHasKey('dbType', $actualArray); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* testGetAndSet |
84
|
|
|
* |
85
|
|
|
* @since 2.2.0 |
86
|
|
|
*/ |
87
|
|
|
|
88
|
|
|
public function testGetAndSet() : void |
89
|
|
|
{ |
90
|
|
|
/* setup */ |
91
|
|
|
|
92
|
|
|
$this->_config->set('dbHost', 'localhost'); |
93
|
|
|
|
94
|
|
|
/* actual */ |
95
|
|
|
|
96
|
|
|
$actual = $this->_config->get('dbHost'); |
97
|
|
|
|
98
|
|
|
/* compare */ |
99
|
|
|
|
100
|
|
|
$this->assertEquals('localhost', $actual); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* testGetArray |
105
|
|
|
* |
106
|
|
|
* @since 4.0.0 |
107
|
|
|
*/ |
108
|
|
|
|
109
|
|
|
public function testGetArray() : void |
110
|
|
|
{ |
111
|
|
|
/* actual */ |
112
|
|
|
|
113
|
|
|
$actualArray = $this->_config->getArray(); |
114
|
|
|
|
115
|
|
|
/* compare */ |
116
|
|
|
|
117
|
|
|
$this->assertArrayHasKey('dbHost', $actualArray); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* testParse |
122
|
|
|
* |
123
|
|
|
* @since 3.0.0 |
124
|
|
|
* |
125
|
|
|
* @param string $dbUrl |
126
|
|
|
* @param array $configArray |
127
|
|
|
* |
128
|
|
|
* @dataProvider providerAutoloader |
129
|
|
|
*/ |
130
|
|
|
|
131
|
|
|
public function testParse(string $dbUrl = null, array $configArray = []) : void |
132
|
|
|
{ |
133
|
|
|
/* setup */ |
134
|
|
|
|
135
|
|
|
$this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
136
|
|
|
$this->_config->parse($dbUrl); |
137
|
|
|
|
138
|
|
|
/* actual */ |
139
|
|
|
|
140
|
|
|
$actual = $this->_config->getArray(); |
141
|
|
|
|
142
|
|
|
/* compare */ |
143
|
|
|
|
144
|
|
|
$this->assertEquals($configArray, $actual); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* testWrite |
149
|
|
|
* |
150
|
|
|
* @since 2.4.0 |
151
|
|
|
*/ |
152
|
|
|
|
153
|
|
|
public function testWrite() : void |
154
|
|
|
{ |
155
|
|
|
/* setup */ |
156
|
|
|
|
157
|
|
|
$this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
158
|
|
|
|
159
|
|
|
/* actual */ |
160
|
|
|
|
161
|
|
|
$actual = $this->_config->write(); |
162
|
|
|
|
163
|
|
|
/* compare */ |
164
|
|
|
|
165
|
|
|
$this->assertNotFalse($actual); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|