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