Passed
Branch master (4b23d6)
by Tim
04:40
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
eloc 9
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
cc 2
nc 4
nop 0
1
<?php
2
3
namespace SimpleSAML\Module\Monitor\TestCase\Store;
4
5
use SimpleSAML\Module\Monitor\State;
6
use SimpleSAML\Module\Monitor\TestData;
7
use SimpleSAML\Module\Monitor\TestResult;
8
9
final class Sql extends \SimpleSAML\Module\Monitor\TestCaseFactory
10
{
11
    /** @var string */
12
    private $host = '<< unset >>';
13
14
15
    /**
16
     * @param \SimpleSAML\Module\Monitor\TestData $testData
17
     *
18
     * @return void
19
     */
20
    protected function initialize(TestData $testData): void
21
    {
22
        $this->host = $testData->getInputItem('host');
23
        parent::initialize($testData);
24
    }
25
26
27
    /**
28
     * @return void
29
     */
30
    public function invokeTest(): void
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