1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor; |
4
|
|
|
|
5
|
|
|
abstract class TestSuiteFactory extends TestFactory |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var array |
9
|
|
|
*/ |
10
|
|
|
private $testResults = array(); |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param TestConfiguration|null $configuration |
14
|
|
|
* @param TestData|null $testData |
15
|
|
|
*/ |
16
|
|
|
public function __construct($configuration = null, $testData = null) |
17
|
|
|
{ |
18
|
|
|
assert($configuration instanceof TestConfiguration || is_null($configuration)); |
19
|
|
|
assert($testData instanceof TestData || is_null($testData)); |
20
|
|
|
|
21
|
|
|
$this->setConfiguration($configuration); |
22
|
|
|
$this->initialize($testData); |
23
|
|
|
$this->invokeTestSuite(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param TestData|null $testData |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
protected function initialize($testData = null) |
32
|
|
|
{ |
33
|
|
|
$this->setTestData($testData); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param TestResult $testResult |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
protected function addTestResult($testResult) |
42
|
|
|
{ |
43
|
|
|
assert($testResult instanceof TestResult); |
44
|
|
|
$this->testResults[] = $testResult; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function getTestResults() |
51
|
|
|
{ |
52
|
|
|
assert(is_array($this->testResults)); |
53
|
|
|
return $this->testResults; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return State |
58
|
|
|
*/ |
59
|
|
|
protected function calculateState() |
60
|
|
|
{ |
61
|
|
|
$testResults = $this->getTestResults(); |
62
|
|
|
$state = State::NOSTATE; |
63
|
|
|
|
64
|
|
|
if (!empty($testResults)) { |
65
|
|
|
$overall = array(); |
66
|
|
|
foreach ($testResults as $testResult) { |
67
|
|
|
$overall[] = $testResult->getState(); |
68
|
|
|
} |
69
|
|
|
$state = min($overall); |
70
|
|
|
} |
71
|
|
|
return $state; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
abstract protected function invokeTestSuite(); |
78
|
|
|
} |
79
|
|
|
|