ConfigTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A synopsis() 0 31 2
A testExceptionThrownWhenConfigIsAppended() 0 5 1
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 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