Passed
Push — develop ( b56629...ffa5e1 )
by Mathieu
01:38
created

SuricateTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 47
dl 0
loc 72
rs 10
c 3
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConfigFile() 0 37 1
A testDefaultConfig() 0 20 1
A testConfigConst() 0 9 1
1
<?php
2
class SuricateTest extends \PHPUnit\Framework\TestCase
3
{
4
    public function testConfigFile()
5
    {
6
        // Empty config files list at the beginning
7
        $object = new \Suricate\Suricate();
8
        $reflectionClass = new ReflectionClass($object);
9
        $property = $reflectionClass->getProperty('configFile');
10
        $property->setAccessible(true);
11
        $configFiles = $property->getValue($object);
12
13
        $this->assertEquals([], $configFiles);
14
15
        // single config file
16
        $object = new \Suricate\Suricate([], './tests/stubs/my-single-config.ini');
17
        $reflectionClass = new ReflectionClass($object);
18
        $property = $reflectionClass->getProperty('configFile');
19
        $property->setAccessible(true);
20
        $configFiles = $property->getValue($object);
21
22
        $this->assertEquals(['./tests/stubs/my-single-config.ini'], $configFiles);
23
24
        // multiple config file
25
        $object = new \Suricate\Suricate([], ['./tests/stubs/my-single-config.ini', './tests/stubs/another-config.ini']);
26
        $reflectionClass = new ReflectionClass($object);
27
        $property = $reflectionClass->getProperty('configFile');
28
        $property->setAccessible(true);
29
        $configFiles = $property->getValue($object);
30
31
        $this->assertEquals(['./tests/stubs/my-single-config.ini', './tests/stubs/another-config.ini'], $configFiles);
32
33
        // non existent file
34
        $object = new \Suricate\Suricate([], ['./tests/stubs/my-single-config-unknown.ini', './tests/stubs/another-config.ini']);
35
        $reflectionClass = new ReflectionClass($object);
36
        $property = $reflectionClass->getProperty('configFile');
37
        $property->setAccessible(true);
38
        $configFiles = $property->getValue($object);
39
40
        $this->assertEquals(['./tests/stubs/another-config.ini'], $configFiles);
41
    }
42
43
    public function testDefaultConfig()
44
    {
45
        $suricate = new Suricate\Suricate();
46
        $this->assertTrue($suricate->hasService('Logger'));
47
        $this->assertTrue($suricate->hasService('Error'));
48
        $this->assertFalse($suricate->hasService('Session'));
49
        
50
        $this->assertEquals([
51
            'Router'    => [],
52
            'Logger'    => [
53
                'enabled'   => true,
54
                'level'     => \Suricate\Logger::LOGLEVEL_WARN,
55
                'logfile'   => 'php://stdout',
56
            ],
57
            'App'       => ['base_uri' => '/'],
58
            'Error'     => [
59
                'report' => true,
60
                'dumpContext' => true,
61
            ],
62
        ], $suricate->getConfig());
63
    }
64
65
    public function testConfigConst()
66
    {
67
        $object = new \Suricate\Suricate([], './tests/stubs/const.ini');
0 ignored issues
show
Unused Code introduced by
The assignment to $object is dead and can be removed.
Loading history...
68
        $this->assertTrue(defined('MY_TEST_CONST'));
69
        $this->assertFalse(defined('my_test_const'));
70
        $this->assertSame(1, MY_TEST_CONST);
0 ignored issues
show
Bug introduced by
The constant MY_TEST_CONST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
        $this->assertSame("my string", ANOTHER_CONST);
0 ignored issues
show
Bug introduced by
The constant ANOTHER_CONST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
72
        $this->assertTrue(ITS_TRUE);
0 ignored issues
show
Bug introduced by
The constant ITS_TRUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
73
        $this->assertSame(true, ITS_TRUE);
74
    }
75
76
}
77