|
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'); |
|
|
|
|
|
|
68
|
|
|
$this->assertTrue(defined('MY_TEST_CONST')); |
|
69
|
|
|
$this->assertFalse(defined('my_test_const')); |
|
70
|
|
|
$this->assertSame(1, MY_TEST_CONST); |
|
|
|
|
|
|
71
|
|
|
$this->assertSame("my string", ANOTHER_CONST); |
|
|
|
|
|
|
72
|
|
|
$this->assertTrue(ITS_TRUE); |
|
|
|
|
|
|
73
|
|
|
$this->assertSame(true, ITS_TRUE); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|