Passed
Push — master ( 2ae391...d44a24 )
by Tim
01:28
created

TestSqlTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSqlFailure() 0 17 1
A testSqlSuccess() 0 17 1
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
if (method_exists('\SimpleSAML_Configuration', 'setPreLoadedConfig')) {
9
10
/**
11
 * Tests for Sql
12
 */
13
class TestSqlTest extends \SimpleSAML\Test\Utils\ClearStateTestCase
14
{
15
    public function testSqlSuccess()
16
    {
17
        $globalConfig_input = [
18
            'store.type' => 'sql',
19
            'store.sql.dsn' => 'sqlite:/modules/monitor/tests/files/test.sqlite',
20
            'store.sql.username' => 'test',
21
            'store.sql.password' => 'test',
22
            'store.sql.options' => null,
23
            'store.sql.prefix' => 'test'
24
        ];
25
26
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
27
        \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

27
        \SimpleSAML_Configuration::/** @scrutinizer ignore-call */ 
28
                                   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...
28
29
        $test = new Sql($globalConfig);
0 ignored issues
show
Bug introduced by
$globalConfig of type SimpleSAML_Configuration is incompatible with the type SimpleSAML\Module\monitor\TestData expected by parameter $testData of SimpleSAML\Module\monito...tore\Sql::__construct(). ( Ignorable by Annotation )

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

29
        $test = new Sql(/** @scrutinizer ignore-type */ $globalConfig);
Loading history...
30
        $testResult = $test->getTestResult();
31
        $this->assertEquals(State::OK, $testResult->getState());
32
    }
33
34
    public function testSqlFailure()
35
    {
36
        $globalConfig_input = [
37
            'store.type' => 'sql',
38
            'store.sql.dsn' => '',
39
            'store.sql.username' => '',
40
            'store.sql.password' => '',
41
            'store.sql.options' => null,
42
            'store.sql.prefix' => 'test'
43
        ];
44
45
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
46
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
47
48
        $test = new Sql($globalConfig);
0 ignored issues
show
Bug introduced by
$globalConfig of type SimpleSAML_Configuration is incompatible with the type SimpleSAML\Module\monitor\TestData expected by parameter $testData of SimpleSAML\Module\monito...tore\Sql::__construct(). ( Ignorable by Annotation )

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

48
        $test = new Sql(/** @scrutinizer ignore-type */ $globalConfig);
Loading history...
49
        $testResult = $test->getTestResult();
50
        $this->assertEquals(State::FATAL, $testResult->getState());
51
    }
52
}
53
54
}
55