Passed
Push — master ( b70a53...6df7c6 )
by Tim
01:59
created

TestSqlTest::testSqlSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
rs 9.4285
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 setUp()
14
    {
15
        if (!method_exists(\SimpleSAML_Configuration, 'setPreLoadedConfig')) {
0 ignored issues
show
Bug introduced by
The constant SimpleSAML_Configuration was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
            $this->markTestSkipped('A preconditiion was not met.');
17
        }
18
    }
19
20
    public function testSqlSuccess()
21
    {
22
        $globalConfig_input = [
23
            'store.type' => 'sql',
24
            'store.sql.dsn' => 'sqlite:/modules/monitor/tests/files/test.sqlite',
25
            'store.sql.username' => 'test',
26
            'store.sql.password' => 'test',
27
            'store.sql.options' => null,
28
            'store.sql.prefix' => 'test'
29
        ];
30
31
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
32
        \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

32
        \SimpleSAML_Configuration::/** @scrutinizer ignore-call */ 
33
                                   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...
33
34
        $testResult = $test->getTestResult();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $test seems to be never defined.
Loading history...
35
        $this->assertEquals(State::OK, $testResult->getState());
36
    }
37
38
    public function testSqlFailure()
39
    {
40
        $globalConfig_input = [
41
            'store.type' => 'sql',
42
            'store.sql.dsn' => '',
43
            'store.sql.username' => '',
44
            'store.sql.password' => '',
45
            'store.sql.options' => null,
46
            'store.sql.prefix' => 'test'
47
        ];
48
49
        $globalConfig = \SimpleSAML_Configuration::loadFromArray($globalConfig_input);
50
        \SimpleSAML_Configuration::setPreLoadedConfig($globalConfig, 'config.php');
51
52
        $test = new Sql();
0 ignored issues
show
Bug introduced by
The call to SimpleSAML\Module\monito...tore\Sql::__construct() has too few arguments starting with testData. ( Ignorable by Annotation )

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

52
        $test = /** @scrutinizer ignore-call */ new Sql();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
53
        $testResult = $test->getTestResult();
54
        $this->assertEquals(State::FATAL, $testResult->getState());
55
    }
56
}
57