Passed
Push — master ( 687fb3...2ae391 )
by Tim
01:37
created

TestSqlTest::testSqlBogus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
/**
9
 * Tests for Sql
10
 */
11
class TestSqlTest extends \SimpleSAML\Test\Utils\ClearStateTestCase
12
{
13
    public function testSqlBogus()
14
    {
15
        $this->addToAssertionCount(1);
16
    }
17
18
    public function testSqlSuccess()
19
    {
20
        if (!method_exists('\SimpleSAML_Configuration', 'setPreLoadedConfig')) {
21
            $this->markTestIncomplete('A precondition was not met.');
22
        }
23
        $globalConfig_input = [
24
            'store.type' => 'sql',
25
            'store.sql.dsn' => 'sqlite:/modules/monitor/tests/files/test.sqlite',
26
            'store.sql.username' => 'test',
27
            'store.sql.password' => 'test',
28
            'store.sql.options' => null,
29
            'store.sql.prefix' => 'test'
30
        ];
31
32
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
33
        \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

33
        \SimpleSAML_Configuration::/** @scrutinizer ignore-call */ 
34
                                   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...
34
35
        $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

35
        $test = new Sql(/** @scrutinizer ignore-type */ $globalConfig);
Loading history...
36
        $testResult = $test->getTestResult();
37
        $this->assertEquals(State::OK, $testResult->getState());
38
    }
39
40
    public function testSqlFailure()
41
    {
42
        if (!method_exists('\SimpleSAML_Configuration', 'setPreLoadedConfig')) {
43
            $this->markTestIncomplete('A precondition was not met.');
44
        }
45
        $globalConfig_input = [
46
            'store.type' => 'sql',
47
            'store.sql.dsn' => '',
48
            'store.sql.username' => '',
49
            'store.sql.password' => '',
50
            'store.sql.options' => null,
51
            'store.sql.prefix' => 'test'
52
        ];
53
54
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
55
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
56
57
        $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

57
        $test = new Sql(/** @scrutinizer ignore-type */ $globalConfig);
Loading history...
58
        $testResult = $test->getTestResult();
59
        $this->assertEquals(State::FATAL, $testResult->getState());
60
    }
61
}
62