|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vectorface\SnappyRouterTests\Config; |
|
4
|
|
|
|
|
5
|
|
|
use \PHPUnit_Framework_TestCase; |
|
6
|
|
|
use Vectorface\SnappyRouter\Config\Config; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Tests the config wrapper class for the router. |
|
10
|
|
|
* @copyright Copyright (c) 2014, VectorFace, Inc. |
|
11
|
|
|
* @author Dan Bruce <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class ConfigTest extends PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Demonstrates basic usage of the Config wrapper class. |
|
17
|
|
|
* @test |
|
18
|
|
|
*/ |
|
19
|
|
|
public function synopsis() |
|
20
|
|
|
{ |
|
21
|
|
|
$arrayConfig = array( |
|
22
|
|
|
'key1' => 'value1', |
|
23
|
|
|
'key2' => 'value2' |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
// initialize the class from an array |
|
27
|
|
|
$config = new Config($arrayConfig); |
|
28
|
|
|
|
|
29
|
|
|
// assert all the keys and values match |
|
30
|
|
|
foreach ($arrayConfig as $key => $value) { |
|
31
|
|
|
// using the array accessor syntax |
|
32
|
|
|
$this->assertEquals($value, $config[$key]); |
|
33
|
|
|
// using the get method |
|
34
|
|
|
$this->assertEquals($value, $config->get($key)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$config['key3'] = 'value3'; |
|
38
|
|
|
$this->assertEquals('value3', $config['key3']); |
|
39
|
|
|
|
|
40
|
|
|
$config->set('key4', 'value4'); |
|
41
|
|
|
$this->assertEquals('value4', $config['key4']); |
|
42
|
|
|
|
|
43
|
|
|
unset($config['key4']); |
|
44
|
|
|
$this->assertNull($config['key4']); // assert we unset the value |
|
45
|
|
|
$this->assertEquals(false, $config->get('key4', false)); // test default values |
|
46
|
|
|
|
|
47
|
|
|
unset($config['key3']); |
|
48
|
|
|
$this->assertEquals($arrayConfig, $config->toArray()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Test that we cannot append to the config class like we would a normal array. |
|
53
|
|
|
* @expectedException \Exception |
|
54
|
|
|
* @expectedExceptionMessage Config values must contain a key. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testExceptionThrownWhenConfigIsAppended() |
|
57
|
|
|
{ |
|
58
|
|
|
$config = new Config(array()); |
|
59
|
|
|
$config[] = 'new value'; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|