|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace KochTest\Config; |
|
4
|
|
|
|
|
5
|
|
|
use Koch\Config\Config; |
|
6
|
|
|
use org\bovigo\vfs\vfsStream; |
|
7
|
|
|
use org\bovigo\vfs\vfsStreamDirectory; |
|
8
|
|
|
use org\bovigo\vfs\vfsStreamWrapper; |
|
9
|
|
|
|
|
10
|
|
|
class ConfigTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Config |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $object; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
19
|
|
|
* This method is called before a test is executed. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->object = new Config(); |
|
24
|
|
|
|
|
25
|
|
|
vfsStreamWrapper::register(); |
|
26
|
|
|
|
|
27
|
|
|
$root = vfsStream::setup('root'); |
|
28
|
|
|
|
|
29
|
|
|
$this->moduleConfigFileURL = vfsStream::url('root/module.config.php'); |
|
|
|
|
|
|
30
|
|
|
$this->file = vfsStream::newFile('module.config.php', 0777)->at($root) |
|
|
|
|
|
|
31
|
|
|
->withContent($this->getModuleConfigFileContent()); |
|
32
|
|
|
|
|
33
|
|
|
$this->applicationConfigFileURL = vfsStream::url('root/application.config.php'); |
|
|
|
|
|
|
34
|
|
|
$this->file2 = vfsStream::newFile('application.config.php', 0777)->at($root) |
|
|
|
|
|
|
35
|
|
|
->withContent($this->getApplicationConfigFileContent()); |
|
36
|
|
|
|
|
37
|
|
|
$this->root = new vfsStreamDirectory('root'); |
|
|
|
|
|
|
38
|
|
|
$this->root->addChild($this->file); |
|
39
|
|
|
$this->root->addChild($this->file2); |
|
40
|
|
|
vfsStreamWrapper::setRoot($this->root); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Tears down the fixture, for example, closes a network connection. |
|
45
|
|
|
* This method is called after a test is executed. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function tearDown() |
|
48
|
|
|
{ |
|
49
|
|
|
unset($this->object); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getModuleConfigFileContent() |
|
53
|
|
|
{ |
|
54
|
|
|
return <<<EOF |
|
55
|
|
|
<?php |
|
56
|
|
|
// Module Configuration File generated by Koch Framework. |
|
57
|
|
|
return array( |
|
58
|
|
|
"module" => "value" |
|
59
|
|
|
); |
|
60
|
|
|
EOF; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getApplicationConfigFileContent() |
|
64
|
|
|
{ |
|
65
|
|
|
return <<<EOF |
|
66
|
|
|
<?php |
|
67
|
|
|
// Application Configuration File generated by Koch Framework. |
|
68
|
|
|
return array( |
|
69
|
|
|
"app" => "value" |
|
70
|
|
|
); |
|
71
|
|
|
EOF; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @covers Koch\Config\Config::read |
|
76
|
|
|
* |
|
77
|
|
|
* @todo Implement testread(). |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testread() |
|
80
|
|
|
{ |
|
81
|
|
|
$config = $this->object->read($this->moduleConfigFileURL); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertTrue(is_array($config)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @covers Koch\Config\Config::readModuleConfig |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testReadModuleConfig() |
|
90
|
|
|
{ |
|
91
|
|
|
$config = $this->object->readModuleConfig('articles'); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertTrue(is_array($config)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @covers Koch\Config\Config::writeModuleConfig |
|
98
|
|
|
*/ |
|
99
|
|
|
public function testWriteModuleConfig() |
|
100
|
|
|
{ |
|
101
|
|
|
$array = ['module' => 'value']; |
|
102
|
|
|
|
|
103
|
|
|
$this->assertTrue($this->object->writeModuleConfig($array, 'Articles')); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @covers Koch\Config\Config::write |
|
108
|
|
|
*/ |
|
109
|
|
|
public function testwrite() |
|
110
|
|
|
{ |
|
111
|
|
|
$file = 'test.config.php'; |
|
112
|
|
|
$array = ['key' => 'value']; |
|
113
|
|
|
|
|
114
|
|
|
$this->assertTrue($this->object->write($file, $array)); |
|
115
|
|
|
|
|
116
|
|
|
if (is_file($file)) { |
|
117
|
|
|
unlink($file); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @covers Koch\Config\Config::write |
|
123
|
|
|
*/ |
|
124
|
|
|
public function testGetApplicationConfig() |
|
125
|
|
|
{ |
|
126
|
|
|
$config = $this->object->getApplicationConfig(); |
|
127
|
|
|
$this->assertTrue(is_array($config)); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: