-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ConfigTest.php
executable file
·121 lines (110 loc) · 3.29 KB
/
ConfigTest.php
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
114
115
116
117
118
119
120
121
<?php
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/
class ConfigTest extends PHPUnit_Framework_TestCase
{
private $_config = array(
"phalcon" => array(
"baseuri" => "/phalcon/"
),
"models" => array(
"metadata" => "memory"
),
"database" => array(
"adapter" => "mysql",
"host" => "localhost",
"username" => "user",
"password" => "passwd",
"name" => "demo"
),
"test" => array(
"parent" => array(
"property" => 1,
),
"parent" => array(
"property2" => "yeah"
)
)
);
private function _compareConfig($c, $config)
{
foreach ($c as $k => $v) {
$this->assertTrue(isset($config->$k));
if (is_array($v)) {
if (isset($config->$k)) {
foreach ($v as $kk => $vv) {
$this->assertTrue(isset($config->$k->$kk));
if (isset($config->$k->$kk)) {
if (is_array($vv)) {
foreach ($vv as $kkk => $vvv) {
if (isset($config->$k->$kk->$kkk)) {
$this->assertTrue(isset($config->$k->$kk->$kkk));
$this->assertEquals($vvv, $config->$k->$kk->$kkk);
}
}
} else {
$this->assertEquals($vv, $config->$k->$kk);
}
}
}
}
}
}
return true;
}
public function testIniConfig()
{
$config = new Phalcon\Config\Adapter\Ini('unit-tests/config/config.ini');
$this->assertTrue($this->_compareConfig($this->_config, $config));
}
public function testStandarConfig()
{
$config = new Phalcon\Config($this->_config);
$this->_compareConfig($this->_config, $config);
}
public function testStandardConfigSimpleArray()
{
$expectedConfig = Phalcon\Config::__set_state(array(
'database' => Phalcon\Config::__set_state(array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'scott',
'password' => 'cheetah',
'name' => 'test_db',
)),
'other' => array(
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
));
$settings = array(
"database" => array(
"adapter" => "Mysql",
"host" => "localhost",
"username" => "scott",
"password" => "cheetah",
"name" => "test_db",
),
"other" => array(1, 2, 3, 4)
);
$config = new Phalcon\Config($settings);
$this->assertEquals($config, $expectedConfig);
}
}