1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor; |
4
|
|
|
|
5
|
|
|
abstract class TestSuiteFactory extends TestCaseFactory |
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
|
|
|
public 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
|
|
|
public function invokeTestSuite() |
78
|
|
|
{ |
79
|
|
|
$this->invokeTest(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
abstract public function invokeTest(); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.