ConfigTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 120
rs 10
c 3
b 0
f 0
wmc 10
lcom 1
cbo 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A getModuleConfigFileContent() 0 10 1
A getApplicationConfigFileContent() 0 10 1
A testReadModuleConfig() 0 6 1
A testWriteModuleConfig() 0 6 1
A testGetApplicationConfig() 0 5 1
A setUp() 0 21 1
A testread() 0 6 1
A testwrite() 0 11 2
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');
0 ignored issues
show
Bug introduced by
The property moduleConfigFileURL does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
        $this->file                = vfsStream::newFile('module.config.php', 0777)->at($root)
0 ignored issues
show
Bug introduced by
The property file does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
            ->withContent($this->getModuleConfigFileContent());
32
33
        $this->applicationConfigFileURL = vfsStream::url('root/application.config.php');
0 ignored issues
show
Bug introduced by
The property applicationConfigFileURL does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
        $this->file2                    = vfsStream::newFile('application.config.php', 0777)->at($root)
0 ignored issues
show
Bug introduced by
The property file2 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
            ->withContent($this->getApplicationConfigFileContent());
36
37
        $this->root = new vfsStreamDirectory('root');
0 ignored issues
show
Bug introduced by
The property root does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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