Passed
Branch monitor-2.5.x (32aff2)
by Tim
01:33
created

TestSqlTest::testSqlFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\Test;
4
5
use \SimpleSAML\Modules\Monitor\TestCase\Store\Sql as Sql;
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\State as State;
8
9
if (method_exists('\SimpleSAML_Configuration', 'setPreLoadedConfig')) {
10
11
/**
12
 * Tests for Sql
13
 */
14
class TestSqlTest extends \SimpleSAML\Test\Utils\ClearStateTestCase
15
{
16
    public function testSqlSuccess()
17
    {
18
        $globalConfig_input = [
19
            'store.type' => 'sql',
20
            'store.sql.dsn' => 'sqlite:/tmp/test.sqlite',
21
        ];
22
23
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
24
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
0 ignored issues
show
Bug introduced by
The method setPreLoadedConfig() does not exist on SimpleSAML_Configuration. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        \SimpleSAML_Configuration::/** @scrutinizer ignore-call */ 
25
                                   setPreLoadedConfig($globalConfig, 'config.php');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
        $testData = new TestData(['host' => 'test.localhost']);
26
27
        $test = new Sql($testData);
28
        $testResult = $test->getTestResult();
29
        $this->assertEquals(State::OK, $testResult->getState());
30
        unlink('/tmp/test.sqlite');
31
    }
32
33
    public function testSqlFailure()
34
    {
35
        $globalConfig_input = [
36
            'store.type' => 'sql',
37
            'store.sql.dsn' => 'somenonexistingfile',
38
        ];
39
40
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
41
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
42
        $testData = new TestData(['host' => 'test.localhost']);
43
44
        $test = new Sql($testData);
45
        $testResult = $test->getTestResult();
46
        $this->assertEquals(State::FATAL, $testResult->getState());
47
    }
48
}
49
50
}
51