1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\Monitor; |
4
|
|
|
|
5
|
|
|
abstract class TestSuiteFactory extends TestCaseFactory |
6
|
|
|
{ |
7
|
|
|
/** @var \SimpleSAML\Module\Monitor\TestConfiguration */ |
8
|
|
|
private $configuration; |
9
|
|
|
|
10
|
|
|
/** @var array An associative array of name => TestResult pairs */ |
11
|
|
|
private $testResults = []; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param \SimpleSAML\Module\Monitor\TestConfiguration $configuration |
16
|
|
|
* @param \SimpleSAML\Module\Monitor\TestData|null $testData |
17
|
|
|
*/ |
18
|
|
|
public function __construct(TestConfiguration $configuration, TestData $testData = null) |
19
|
|
|
{ |
20
|
|
|
$this->setConfiguration($configuration); |
21
|
|
|
|
22
|
|
|
parent::__construct($testData); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \SimpleSAML\Module\Monitor\TestData|null $testData |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
protected function initialize(TestData $testData = null): void |
32
|
|
|
{ |
33
|
|
|
if (!is_null($testData)) { |
34
|
|
|
parent::initialize($testData); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param \SimpleSAML\Module\Monitor\TestConfiguration $configuration |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
protected function setConfiguration(TestConfiguration $configuration): void |
45
|
|
|
{ |
46
|
|
|
$this->configuration = $configuration; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \SimpleSAML\Module\Monitor\TestConfiguration |
52
|
|
|
*/ |
53
|
|
|
public function getConfiguration(): TestConfiguration |
54
|
|
|
{ |
55
|
|
|
return $this->configuration; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param \SimpleSAML\Module\Monitor\TestResult $testResult |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
protected function addTestResult(TestResult $testResult): void |
65
|
|
|
{ |
66
|
|
|
$this->testResults[] = $testResult; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param array $testResults |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
protected function addTestResults(array $testResults): void |
76
|
|
|
{ |
77
|
|
|
$this->testResults = array_merge($this->testResults, $testResults); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function getTestResults(): array |
85
|
|
|
{ |
86
|
|
|
return $this->testResults; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param bool $includeOutput |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function getArrayizeTestResults(bool $includeOutput = false): array |
96
|
|
|
{ |
97
|
|
|
$result = []; |
98
|
|
|
foreach ($this->testResults as $testResult) { |
99
|
|
|
$result[] = $testResult->arrayizeTestResult($includeOutput); |
100
|
|
|
} |
101
|
|
|
return $result; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return int |
107
|
|
|
*/ |
108
|
|
|
public function calculateState(): int |
109
|
|
|
{ |
110
|
|
|
$testResults = $this->getTestResults(); |
111
|
|
|
|
112
|
|
|
if (!empty($testResults)) { |
113
|
|
|
$state = State::OK; |
114
|
|
|
foreach ($testResults as $testResult) { |
115
|
|
|
$testState = $testResult->getState(); |
116
|
|
|
if ($testState !== State::NOSTATE && $testState !== State::SKIPPED) { |
117
|
|
|
if ($testState < $state) { |
118
|
|
|
$state = $testState; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} else { |
123
|
|
|
$state = State::NOSTATE; |
124
|
|
|
} |
125
|
|
|
return $state; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|