Passed
Push — master ( bdacbe...8366ca )
by Tim
02:21
created

TestSuiteFactory::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
abstract class TestSuiteFactory extends TestCaseFactory
6
{
7
    /**
8
     * @var TestConfiguration
9
     * @deprecated
10
     */
11
    private $configuration;
12
13
    /**
14
     * @var array   An associative array of name => TestResult pairs
15
     */
16
    private $testResults = [];
17
18
    /**
19
     * @param TestConfiguration|null $configuration
20
     * @param TestData|null $testData
21
     */
22
    public function __construct($configuration = null, $testData = null)
23
    {
24
        assert($configuration instanceof TestConfiguration || is_null($configuration));
25
        assert($testData instanceof TestData || is_null($testData));
26
27
        $this->setConfiguration($configuration);
28
        $this->initialize($testData);
29
        $this->invokeTestSuite();
30
    }
31
32
    /**
33
     * @param TestData $testData
34
     *
35
     * @return void
36
     */
37
    protected function initialize($testData)
38
    {
39
        $this->setTestData($testData);
40
    }
41
42
    /**
43
     * @param TestConfiguration|null $configuration
44
     *
45
     * @return void
46
     */
47
    protected function setConfiguration($configuration = null)
48
    {
49
        assert($configuration instanceof TestConfiguration);
50
        if (!is_null($configuration)) {
51
            $this->configuration = $configuration;
0 ignored issues
show
Deprecated Code introduced by
The property SimpleSAML\Module\monito...Factory::$configuration has been deprecated. ( Ignorable by Annotation )

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

51
            /** @scrutinizer ignore-deprecated */ $this->configuration = $configuration;
Loading history...
52
        }
53
    }
54
55
    /**
56
     * @return TestConfiguration
57
     */
58
    public function getConfiguration()
59
    {
60
        assert($this->configuration instanceof TestConfiguration);
0 ignored issues
show
Deprecated Code introduced by
The property SimpleSAML\Module\monito...Factory::$configuration has been deprecated. ( Ignorable by Annotation )

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

60
        assert(/** @scrutinizer ignore-deprecated */ $this->configuration instanceof TestConfiguration);
Loading history...
61
        return $this->configuration;
0 ignored issues
show
Deprecated Code introduced by
The property SimpleSAML\Module\monito...Factory::$configuration has been deprecated. ( Ignorable by Annotation )

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

61
        return /** @scrutinizer ignore-deprecated */ $this->configuration;
Loading history...
62
    }
63
64
    /**
65
     * @param TestResult $testResult
66
     *
67
     * @return void
68
     */
69
    protected function addTestResult($testResult)
70
    {
71
        assert($testResult instanceof TestResult);
72
        $this->testResults[] = $testResult;
73
    }
74
75
    /**
76
     * @param array $testResults
77
     *
78
     * @return void
79
     */
80
    protected function addTestResults($testResults)
81
    {
82
        assert(is_array($testResults));
83
        $this->testResults = array_merge($this->testResults, $testResults);
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getTestResults()
90
    {
91
        assert(is_array($this->testResults));
92
        return $this->testResults;
93
    }
94
95
    /**
96
     * param bool $includeOutput
97
     *
98
     * @return array
99
     */
100
    public function getArrayizeTestResults($includeOutput = false)
101
    {
102
        assert(is_array($this->testResults));
103
        $result = [];
104
        foreach ($this->testResults as $testResult) {
105
            $result[] = $testResult->arrayizeTestResult($includeOutput);
106
        }
107
        return $result;
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function calculateState()
114
    {
115
        $testResults = $this->getTestResults();
116
117
        if (!empty($testResults)) {
118
            $state = State::OK;
119
            foreach ($testResults as $testResult) {
120
                $testState = $testResult->getState();
121
                if ($testState < $state) {
122
                    $state = $testState;
123
                }
124
            }
125
        } else {
126
            $state = State::NOSTATE;
127
        }
128
        return $state;
129
    }
130
131
    /**
132
     * @return void
133
     */
134
    public function invokeTestSuite()
135
    {
136
        $this->invokeTest();
137
    }
138
}
139