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

TestSqlTest::testSqlSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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