Passed
Push — master ( 508b20...f10a99 )
by Tim
01:42
created

TestSqlTest::testSqlSuccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 2
nop 0
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\Test;
4
5
use \SimpleSAML\Module\monitor\TestCase\Store\Sql as Sql;
6
use \SimpleSAML\Module\monitor\State as State;
7
8
/**
9
 * Tests for Sql
10
 */
11
class TestSqlTest extends \SimpleSAML\Test\Utils\ClearStateTestCase
12
{
13
    // This test relies on \SimpleSAML_Configuration::setPreLoadedConfig(), which is not available until after 1.15.4
14
    if (!method_exists('SimpleSAML_Configuration', 'setPreLoadedConfig')) {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_IF, expecting T_FUNCTION or T_CONST on line 14 at column 4
Loading history...
15
        protected function setUp()
16
        {
17
            $this->markTestSkipped('Requires SimpleSAMLphp >1.15.4');
18
        }
19
    }
20
21
    public function testSqlSuccess()
22
    {
23
        $globalConfig_input = [
24
            'store.type' => 'sql',
25
            'store.sql.dsn' => 'sqlite:/modules/monitor/tests/files/test.sqlite',
26
            'store.sql.username' => 'test',
27
            'store.sql.password' => 'test',
28
            'store.sql.options' => null,
29
            'store.sql.prefix' => 'test'
30
        ];
31
32
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
33
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
34
35
        $testResult = $test->getTestResult();
36
        $this->assertEquals(State::OK, $testResult->getState());
37
    }
38
39
    public function testSqlFailure()
40
    {
41
        $globalConfig_input = [
42
            'store.type' => 'sql',
43
            'store.sql.dsn' => '',
44
            'store.sql.username' => '',
45
            'store.sql.password' => '',
46
            'store.sql.options' => null,
47
            'store.sql.prefix' => 'test'
48
        ];
49
50
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
51
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
52
53
        $test = new Sql();
54
        $testResult = $test->getTestResult();
55
        $this->assertEquals(State::FATAL, $testResult->getState());
56
    }
57
}
58