Passed
Push — monitor-3.0.x ( f85cdc...51d4ea )
by Tim
03:29
created

TestSqlTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSqlFailure() 0 14 1
A testSqlSuccess() 0 15 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\TestUtils\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