1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor; |
4
|
|
|
|
5
|
|
|
abstract class TestCaseFactory implements TestInterface |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var string |
9
|
|
|
*/ |
10
|
|
|
private $category; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $subject; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var TestData |
19
|
|
|
*/ |
20
|
|
|
private $testData; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var TestConfiguration |
24
|
|
|
* @deprecated |
25
|
|
|
*/ |
26
|
|
|
private $configuration; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var TestResult |
30
|
|
|
*/ |
31
|
|
|
private $testResult; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param TestData $testData |
35
|
|
|
*/ |
36
|
|
|
public function __construct($testData) |
37
|
|
|
{ |
38
|
|
|
assert($testData instanceof TestData); |
39
|
|
|
|
40
|
|
|
$this->initialize($testData); |
41
|
|
|
$this->invokeTest(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Testdata $testData |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
protected function initialize($testData) |
50
|
|
|
{ |
51
|
|
|
$this->setTestData($testData); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $category |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
protected function setCategory($category) |
60
|
|
|
{ |
61
|
|
|
assert(is_string($category)); |
62
|
|
|
$this->category = $category; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getCategory() |
69
|
|
|
{ |
70
|
|
|
assert(is_string($this->category)); |
71
|
|
|
return $this->category; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param TestConfiguration|null $configuration |
76
|
|
|
* |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
protected function setConfiguration($configuration = null) |
80
|
|
|
{ |
81
|
|
|
assert($configuration instanceof TestConfiguration); |
82
|
|
|
if (!is_null($configuration)) { |
83
|
|
|
$this->configuration = $configuration; |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return TestConfiguration |
89
|
|
|
*/ |
90
|
|
|
public function getConfiguration() |
91
|
|
|
{ |
92
|
|
|
assert($this->configuration instanceof TestConfiguration); |
|
|
|
|
93
|
|
|
return $this->configuration; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return TestData|null |
98
|
|
|
*/ |
99
|
|
|
public function getTestData() |
100
|
|
|
{ |
101
|
|
|
assert($this->testData instanceof TestData || is_null($this->testData)); |
102
|
|
|
return $this->testData; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param TestData|null $testData |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
protected function setTestData($testData = null) |
111
|
|
|
{ |
112
|
|
|
assert($testData instanceof TestData || is_null($testData)); |
113
|
|
|
if (!is_null($testData)) { |
114
|
|
|
$this->testData = $testData; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param TestResult $testResult |
120
|
|
|
* |
121
|
|
|
* @return void |
122
|
|
|
*/ |
123
|
|
|
protected function setTestResult($testResult) |
124
|
|
|
{ |
125
|
|
|
assert($testResult instanceof TestResult); |
126
|
|
|
$this->testResult = $testResult; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return TestResult |
131
|
|
|
*/ |
132
|
|
|
public function getTestResult() |
133
|
|
|
{ |
134
|
|
|
assert($this->testResult instanceof TestResult); |
135
|
|
|
return $this->testResult; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $subject |
140
|
|
|
* |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
protected function setSubject($subject) |
144
|
|
|
{ |
145
|
|
|
assert(is_string($subject)); |
146
|
|
|
$this->subject = $subject; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getSubject() |
153
|
|
|
{ |
154
|
|
|
assert(is_string($this->subject)); |
155
|
|
|
return $this->subject; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
abstract public function invokeTest(); |
159
|
|
|
} |
160
|
|
|
|