suricate-php /
framework
| 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( |
||
| 17 | [], |
||
| 18 | './tests/stubs/my-single-config.ini' |
||
| 19 | ); |
||
| 20 | $reflectionClass = new ReflectionClass($object); |
||
| 21 | $property = $reflectionClass->getProperty('configFile'); |
||
| 22 | $property->setAccessible(true); |
||
| 23 | $configFiles = $property->getValue($object); |
||
| 24 | |||
| 25 | $this->assertEquals( |
||
| 26 | ['./tests/stubs/my-single-config.ini'], |
||
| 27 | $configFiles |
||
| 28 | ); |
||
| 29 | |||
| 30 | // multiple config file |
||
| 31 | $object = new \Suricate\Suricate( |
||
| 32 | [], |
||
| 33 | [ |
||
| 34 | './tests/stubs/my-single-config.ini', |
||
| 35 | './tests/stubs/another-config.ini' |
||
| 36 | ] |
||
| 37 | ); |
||
| 38 | $reflectionClass = new ReflectionClass($object); |
||
| 39 | $property = $reflectionClass->getProperty('configFile'); |
||
| 40 | $property->setAccessible(true); |
||
| 41 | $configFiles = $property->getValue($object); |
||
| 42 | |||
| 43 | $this->assertEquals( |
||
| 44 | [ |
||
| 45 | './tests/stubs/my-single-config.ini', |
||
| 46 | './tests/stubs/another-config.ini' |
||
| 47 | ], |
||
| 48 | $configFiles |
||
| 49 | ); |
||
| 50 | |||
| 51 | // non existent file |
||
| 52 | $object = new \Suricate\Suricate( |
||
| 53 | [], |
||
| 54 | [ |
||
| 55 | './tests/stubs/my-single-config-unknown.ini', |
||
| 56 | './tests/stubs/another-config.ini' |
||
| 57 | ] |
||
| 58 | ); |
||
| 59 | $reflectionClass = new ReflectionClass($object); |
||
| 60 | $property = $reflectionClass->getProperty('configFile'); |
||
| 61 | $property->setAccessible(true); |
||
| 62 | $configFiles = $property->getValue($object); |
||
| 63 | |||
| 64 | $this->assertEquals(['./tests/stubs/another-config.ini'], $configFiles); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function testDefaultConfig() |
||
| 68 | { |
||
| 69 | $suricate = new Suricate\Suricate(); |
||
| 70 | $this->assertTrue($suricate->hasService('Logger')); |
||
| 71 | $this->assertTrue($suricate->hasService('Error')); |
||
| 72 | $this->assertFalse($suricate->hasService('Session')); |
||
| 73 | |||
| 74 | $this->assertEquals( |
||
| 75 | [ |
||
| 76 | 'Router' => [], |
||
| 77 | 'Logger' => [ |
||
| 78 | 'enabled' => true, |
||
| 79 | 'level' => \Suricate\Logger::LOGLEVEL_WARN, |
||
| 80 | 'logfile' => 'php://stdout' |
||
| 81 | ], |
||
| 82 | 'App' => ['base_uri' => '/'], |
||
| 83 | 'Error' => [ |
||
| 84 | 'report' => true, |
||
| 85 | 'dumpContext' => true |
||
| 86 | ] |
||
| 87 | ], |
||
| 88 | $suricate->getConfig() |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function testConfigConst() |
||
| 93 | { |
||
| 94 | $object = new \Suricate\Suricate([], './tests/stubs/const.ini'); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 95 | $this->assertTrue(defined('MY_TEST_CONST')); |
||
| 96 | $this->assertFalse(defined('my_test_const')); |
||
| 97 | $this->assertSame(1, MY_TEST_CONST); |
||
|
0 ignored issues
–
show
|
|||
| 98 | $this->assertSame("my string", ANOTHER_CONST); |
||
|
0 ignored issues
–
show
|
|||
| 99 | $this->assertTrue(ITS_TRUE); |
||
|
0 ignored issues
–
show
|
|||
| 100 | $this->assertSame(true, ITS_TRUE); |
||
| 101 | } |
||
| 102 | } |
||
| 103 |