ConfigManagerTest.php
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace clagiordano\weblibs\configmanager\tests;
use clagiordano\weblibs\configmanager\ConfigManager;
/**
* Class ConfigManagerTest
* @package clagiordano\weblibs\configmanager\tests
*/
class ConfigManagerTest extends \PHPUnit_Framework_TestCase
{
/** @var ConfigManager $config */
private $config = null;
private $configFile = 'testsdata/sample_config_data.php';
public function setUp()
{
$this->config = new ConfigManager("TestConfigData.php");
$this->assertInstanceOf('clagiordano\weblibs\configmanager\ConfigManager', $this->config);
$this->assertFileExists($this->configFile);
$this->config->loadConfig($this->configFile);
}
public function testBasicUsage()
{
$this->assertNotNull(
$this->config->getValue('app')
);
}
public function testFastUsage()
{
$this->assertNotNull(
$this->config->getValue('app')
);
}
public function testFastInvalidKey()
{
$this->assertNull(
$this->config->getValue('invalidKey')
);
}
public function testFastInvalidKeyWithDefault()
{
$this->assertEquals(
$this->config->getValue('invalidKey', 'defaultValue'),
'defaultValue'
);
}
public function testFastNestedConfig()
{
$this->assertNotNull(
$this->config->getValue('other.multi.deep.nested')
);
}
public function testCheckExistConfig()
{
$this->assertTrue(
$this->config->existValue('other.multi.deep.nested')
);
}
public function testCheckNotExistConfig()
{
$this->assertFalse(
$this->config->existValue('invalid.config.path')
);
}
public function testSetValue()
{
$this->config->setValue('other.multi.deep.nested', __FUNCTION__);
$this->assertEquals(
$this->config->getValue('other.multi.deep.nested'),
__FUNCTION__
);
}
public function testFailedSaveConfig()
{
$this->setExpectedException('Exception');
$this->config->saveConfigFile('/invalid/path');
}
public function testSuccessSaveConfigOnTempAndReload()
{
$this->config->setValue('other.multi.deep.nested', "SUPERNESTED");
$this->config->saveConfigFile("/tmp/testconfig.php", true);
$this->assertEquals(
$this->config->getValue('other.multi.deep.nested'),
"SUPERNESTED"
);
}
public function testOverwriteSameConfigFile()
{
$this->config->saveConfigFile();
}
public function testFailWriteConfig()
{
$this->setExpectedException('\RuntimeException');
$this->config->saveConfigFile('/invalid/path/test.php');
}
}