1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\Test\Config; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SKien\Config\NullConfig; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Stefanius <[email protected]> |
11
|
|
|
* @copyright MIT License - see the LICENSE file for details |
12
|
|
|
*/ |
13
|
|
|
class NullConfigTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function test_construct() |
16
|
|
|
{ |
17
|
|
|
$cfg = new NullConfig(); |
18
|
|
|
$this->assertIsObject($cfg); |
19
|
|
|
$this->assertEquals('default', $cfg->getString('BaseString_1', 'default')); |
20
|
|
|
$this->assertEquals(10, $cfg->getInt('Module_1.Int_1', 10)); |
21
|
|
|
$this->assertEquals(12.34, $cfg->getFloat('Module_1.Float_1', 12.34)); |
22
|
|
|
$this->assertEquals(false, $cfg->getBool('Module_1.Bool_X', false)); |
23
|
|
|
$this->assertEquals(true, $cfg->getBool('Module_1.Bool_X', true)); |
24
|
|
|
$this->assertEquals('2021-02-20', date('Y-m-d', $cfg->getDate('Module_1.Date_X', mktime(0, 0, 0, 02, 20, 2021)))); |
25
|
|
|
$this->assertEquals('2021-02-20 16:27', date('Y-m-d H:i', $cfg->getDateTime('Module_1.DateTime_X', mktime(16, 27, 0, 02, 20, 2021)))); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function test_getIndexedArray() : void |
29
|
|
|
{ |
30
|
|
|
$cfg = new NullConfig(); |
31
|
|
|
$aValues = $cfg->getArray('IndexedArray', ['First Element', 'Second Element', 'Third Element']); |
32
|
|
|
$this->assertIsArray($aValues); |
33
|
|
|
$this->assertEquals(3, count($aValues)); |
34
|
|
|
$this->assertEquals('First Element', $aValues[0]); |
35
|
|
|
$this->assertEquals('Second Element', $aValues[1]); |
36
|
|
|
$this->assertEquals('Third Element', $aValues[2]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function test_getAssocArray() : void |
40
|
|
|
{ |
41
|
|
|
$cfg = new NullConfig(); |
42
|
|
|
$aValues = $cfg->getArray('AssocArray', ['First' => 'Element 1', 'Second' => 'Element 2', 'Third' => 'Element 3']); |
43
|
|
|
$this->assertIsArray($aValues); |
44
|
|
|
$this->assertEquals(3, count($aValues)); |
45
|
|
|
$this->assertEquals('Element 1', $aValues['First']); |
46
|
|
|
$this->assertEquals('Element 2', $aValues['Second']); |
47
|
|
|
$this->assertEquals('Element 3', $aValues['Third']); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|