Passed
Branch monitor-3.0.x (ef3617)
by Tim
04:19
created

TestSqlTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSqlSuccess() 0 15 1
A testSqlFailure() 0 14 1
1
<?php
2
3
namespace SimpleSAML\Module\Monitor\Test;
4
5
use SimpleSAML\Module\Monitor\TestCase\Store\Sql;
6
use SimpleSAML\Module\Monitor\TestData;
7
use SimpleSAML\Module\Monitor\State;
8
9
/**
10
 * Tests for Sql
11
 */
12
class TestSqlTest extends \SimpleSAML\Test\Utils\ClearStateTestCase
13
{
14
    public function testSqlSuccess(): void
15
    {
16
        $globalConfig_input = [
17
            'store.type' => 'sql',
18
            'store.sql.dsn' => 'sqlite:/tmp/test.sqlite',
19
        ];
20
21
        $globalConfig = \SimpleSAML\Configuration::loadFromArray($globalConfig_input);
22
        \SimpleSAML\Configuration::setPreLoadedConfig($globalConfig, 'config.php');
23
        $testData = new TestData(['host' => 'test.localhost']);
24
25
        $test = new Sql($testData);
26
        $testResult = $test->getTestResult();
27
        $this->assertEquals(State::OK, $testResult->getState());
28
        unlink('/tmp/test.sqlite');
29
    }
30
31
    public function testSqlFailure(): void
32
    {
33
        $globalConfig_input = [
34
            'store.type' => 'sql',
35
            'store.sql.dsn' => 'somenonexistingfile',
36
        ];
37
38
        $globalConfig = \SimpleSAML\Configuration::loadFromArray($globalConfig_input);
39
        \SimpleSAML\Configuration::setPreLoadedConfig($globalConfig, 'config.php');
40
        $testData = new TestData(['host' => 'test.localhost']);
41
42
        $test = new Sql($testData);
43
        $testResult = $test->getTestResult();
44
        $this->assertEquals(State::FATAL, $testResult->getState());
45
    }
46
}
47