These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Tests\Console\Command; |
||
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 | use Redaxscript\Console\Command; |
||
8 | use Redaxscript\Tests\TestCaseAbstract; |
||
9 | |||
10 | /** |
||
11 | * ConfigTest |
||
12 | * |
||
13 | * @since 3.0.0 |
||
14 | * |
||
15 | * @package Redaxscript |
||
16 | * @category Tests |
||
17 | * @author Henry Ruhs |
||
18 | * |
||
19 | * @covers Redaxscript\Console\Command\Config |
||
20 | * @covers Redaxscript\Console\Command\CommandAbstract |
||
21 | */ |
||
22 | |||
23 | class ConfigTest extends TestCaseAbstract |
||
24 | { |
||
25 | /** |
||
26 | * array to restore config |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | |||
31 | protected $_configArray = []; |
||
32 | |||
33 | /** |
||
34 | * setUp |
||
35 | * |
||
36 | * @since 3.0.0 |
||
37 | */ |
||
38 | |||
39 | public function setUp() : void |
||
40 | { |
||
41 | parent::setUp(); |
||
42 | Stream::setup('root'); |
||
43 | $file = new StreamFile('config.php'); |
||
44 | StreamWrapper::getRoot()->addChild($file); |
||
45 | $this->_configArray = $this->_config->get(); |
||
0 ignored issues
–
show
|
|||
46 | } |
||
47 | |||
48 | /** |
||
49 | * tearDown |
||
50 | * |
||
51 | * @since 3.1.0 |
||
52 | */ |
||
53 | |||
54 | public function tearDown() : void |
||
55 | { |
||
56 | $this->_config->set('dbType', $this->_configArray['dbType']); |
||
57 | $this->_config->set('dbHost', $this->_configArray['dbHost']); |
||
58 | $this->_config->set('dbPrefix', $this->_configArray['dbPrefix']); |
||
59 | $this->_config->set('dbName', $this->_configArray['dbName']); |
||
60 | $this->_config->set('dbUser', $this->_configArray['dbUser']); |
||
61 | $this->_config->set('dbPassword', $this->_configArray['dbPassword']); |
||
62 | $this->_config->set('env', $this->_configArray['env']); |
||
63 | $this->_request->setServer('argv', null); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * testNoArgument |
||
68 | * |
||
69 | * @since 3.0.0 |
||
70 | */ |
||
71 | |||
72 | public function testNoArgument() : void |
||
73 | { |
||
74 | /* setup */ |
||
75 | |||
76 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
77 | |||
78 | /* expect and actual */ |
||
79 | |||
80 | $expect = $configCommand->getHelp(); |
||
81 | $actual = $configCommand->run('cli'); |
||
82 | |||
83 | /* compare */ |
||
84 | |||
85 | $this->assertEquals($expect, $actual); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * testList |
||
90 | * |
||
91 | * @since 3.0.0 |
||
92 | */ |
||
93 | |||
94 | public function testList() : void |
||
95 | { |
||
96 | /* setup */ |
||
97 | |||
98 | $this->_config->set('dbPassword', 'test'); |
||
99 | $this->_request->setServer('argv', |
||
100 | [ |
||
101 | 'console.php', |
||
102 | 'config', |
||
103 | 'list' |
||
104 | ]); |
||
105 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
106 | |||
107 | /* actual */ |
||
108 | |||
109 | $actual = $configCommand->run('cli'); |
||
110 | |||
111 | /* compare */ |
||
112 | |||
113 | $this->assertIsString($actual); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * testSet |
||
118 | * |
||
119 | * @since 3.0.0 |
||
120 | */ |
||
121 | |||
122 | public function testSet() : void |
||
123 | { |
||
124 | /* setup */ |
||
125 | |||
126 | $this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
||
127 | $this->_request->setServer('argv', |
||
128 | [ |
||
129 | 'console.php', |
||
130 | 'config', |
||
131 | 'set', |
||
132 | '--db-type', |
||
133 | 'sqlite', |
||
134 | '--db-host', |
||
135 | '127.0.0.1' |
||
136 | ]); |
||
137 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
138 | |||
139 | /* expect and actual */ |
||
140 | |||
141 | $expect = $configCommand->success(); |
||
142 | $actual = $configCommand->run('cli'); |
||
143 | |||
144 | /* compare */ |
||
145 | |||
146 | $this->assertEquals($expect, $actual); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * testSetInvalid |
||
151 | * |
||
152 | * @since 3.0.0 |
||
153 | */ |
||
154 | |||
155 | public function testSetInvalid() : void |
||
156 | { |
||
157 | /* setup */ |
||
158 | |||
159 | $this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
||
160 | $this->_request->setServer('argv', |
||
161 | [ |
||
162 | 'console.php', |
||
163 | 'config', |
||
164 | 'set', |
||
165 | '--no-interaction' |
||
166 | ]); |
||
167 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
168 | |||
169 | /* expect and actual */ |
||
170 | |||
171 | $expect = $configCommand->error(); |
||
172 | $actual = $configCommand->run('cli'); |
||
173 | |||
174 | /* compare */ |
||
175 | |||
176 | $this->assertEquals($expect, $actual); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * testParse |
||
181 | * |
||
182 | * @since 3.0.0 |
||
183 | */ |
||
184 | |||
185 | public function testParse() : void |
||
186 | { |
||
187 | /* setup */ |
||
188 | |||
189 | $this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
||
190 | $this->_request->setServer('argv', |
||
191 | [ |
||
192 | 'console.php', |
||
193 | 'config', |
||
194 | 'parse', |
||
195 | '--db-url', |
||
196 | '$DB_URL' |
||
197 | ]); |
||
198 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
199 | |||
200 | /* expect and actual */ |
||
201 | |||
202 | $expect = $configCommand->success(); |
||
203 | $actual = $configCommand->run('cli'); |
||
204 | |||
205 | /* compare */ |
||
206 | |||
207 | $this->assertEquals($expect, $actual); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * testParseInvalid |
||
212 | * |
||
213 | * @since 3.0.0 |
||
214 | */ |
||
215 | |||
216 | public function testParseInvalid() : void |
||
217 | { |
||
218 | /* setup */ |
||
219 | |||
220 | $this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
||
221 | $this->_request->setServer('argv', |
||
222 | [ |
||
223 | 'console.php', |
||
224 | 'config', |
||
225 | 'parse', |
||
226 | '--no-interaction' |
||
227 | ]); |
||
228 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
229 | |||
230 | /* expect and actual */ |
||
231 | |||
232 | $expect = $configCommand->error(); |
||
233 | $actual = $configCommand->run('cli'); |
||
234 | |||
235 | /* compare */ |
||
236 | |||
237 | $this->assertEquals($expect, $actual); |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * testLock |
||
242 | * |
||
243 | * @since 3.0.0 |
||
244 | */ |
||
245 | |||
246 | public function testLock() : void |
||
247 | { |
||
248 | /* setup */ |
||
249 | |||
250 | $this->_config->init(Stream::url('root' . DIRECTORY_SEPARATOR . 'config.php')); |
||
251 | $this->_request->setServer('argv', |
||
252 | [ |
||
253 | 'console.php', |
||
254 | 'config', |
||
255 | 'lock' |
||
256 | ]); |
||
257 | $configCommand = new Command\Config($this->_registry, $this->_request, $this->_language, $this->_config); |
||
258 | |||
259 | /* expect and actual */ |
||
260 | |||
261 | $expect = $configCommand->success(); |
||
262 | $actual = $configCommand->run('cli'); |
||
263 | |||
264 | /* compare */ |
||
265 | |||
266 | $this->assertEquals($expect, $actual); |
||
267 | } |
||
268 | } |
||
269 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.