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

Sql::invokeTest()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 4
nop 0
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\Store;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
final class Sql extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var string|null
13
     */
14
    private $host;
15
16
    /**
17
     * @param TestData $testData
18
     *
19
     * @return void
20
     */
21
    protected function initialize($testData)
22
    {
23
        $this->host = $testData->getInputItem('host');
24
        parent::initialize($testData);
25
    }
26
27
    /**
28
     * @return void
29
     */
30
    public function invokeTest()
31
    {
32
        $testResult = new TestResult('SQL Server Health', $this->host);
33
34
        try {
35
            new \SimpleSAML\Store\SQL();
36
            $testResult->setState(State::OK);
37
            $testResult->setMessage('Connection to the database succesfully established');
38
        } catch (\Exception $e) {
39
            $testResult->setState(State::FATAL);
40
            $testResult->setMessage('Unable to connect to the database; '.$e->getMessage());
41
        }
42
43
        $this->setTestResult($testResult);
44
    }
45
}
46