|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor; |
|
4
|
|
|
|
|
5
|
|
|
abstract class TestFactory |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var TestData |
|
9
|
|
|
*/ |
|
10
|
|
|
private $testData; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var TestConfiguration|null |
|
14
|
|
|
*/ |
|
15
|
|
|
private $configuration = null; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array<TestResult> |
|
19
|
|
|
*/ |
|
20
|
|
|
private $testResult; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array|null |
|
24
|
|
|
*/ |
|
25
|
|
|
private $output = array(); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var State |
|
29
|
|
|
*/ |
|
30
|
|
|
private $state = State::NOSTATE; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
private $messages = array(); |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param TestConfiguration|null $configuration |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function setConfiguration($configuration = null) |
|
44
|
|
|
{ |
|
45
|
|
|
assert($configuration instanceof TestConfiguration); |
|
46
|
|
|
if (!is_null($configuration)) { |
|
47
|
|
|
$this->configuration = $configuration; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return TestConfiguration |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getConfiguration() |
|
56
|
|
|
{ |
|
57
|
|
|
assert($this->configuration instanceof TestConfiguration); |
|
58
|
|
|
return $this->configuration; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return TestData|null |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getTestData() |
|
66
|
|
|
{ |
|
67
|
|
|
assert($this->testData instanceof TestData || is_null($this->testData)); |
|
68
|
|
|
return $this->testData; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param TestData|null $testData |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function setTestData($testData = null) |
|
78
|
|
|
{ |
|
79
|
|
|
assert($testData instanceof TestData || is_null($testData)); |
|
80
|
|
|
if (!is_null($testData)) { |
|
81
|
|
|
$this->testData = $testData; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param TestResult $testResult |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function setTestResult($testResult) |
|
92
|
|
|
{ |
|
93
|
|
|
assert($testResult instanceof TestResult); |
|
94
|
|
|
$this->testResult = $testResult; |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param TestResult $testResult |
|
100
|
|
|
* |
|
101
|
|
|
* @return void |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function addTestResult($testResult) |
|
104
|
|
|
{ |
|
105
|
|
|
assert($testResult instanceof TestResult); |
|
106
|
|
|
$this->testResult[] = $testResult; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return TestResult |
|
|
|
|
|
|
112
|
|
|
*/ |
|
113
|
|
|
public function getTestResult() |
|
114
|
|
|
{ |
|
115
|
|
|
assert($this->testResult instanceof TestResult); |
|
116
|
|
|
return $this->testResult; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return array |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getMessages() |
|
124
|
|
|
{ |
|
125
|
|
|
assert(is_array($this->messages)); |
|
126
|
|
|
return $this->messages; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param string|null $item |
|
132
|
|
|
* |
|
133
|
|
|
* @return mixed |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getOutput($item = null) |
|
136
|
|
|
{ |
|
137
|
|
|
assert(is_string($item) || is_null($item)); |
|
138
|
|
|
return is_null($item) ? $this->output : (isSet($this->output[$item]) ? $this->output[$item] : null); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return State |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getState() |
|
146
|
|
|
{ |
|
147
|
|
|
assert($this->state instanceof State); |
|
148
|
|
|
return $this->state; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return void |
|
154
|
|
|
*/ |
|
155
|
|
|
protected function setMessages($messages) |
|
156
|
|
|
{ |
|
157
|
|
|
assert(is_array($messages)); |
|
158
|
|
|
$this->messages = $messages; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @param array $messages |
|
164
|
|
|
* @param string|null $index |
|
165
|
|
|
* |
|
166
|
|
|
* @return void |
|
167
|
|
|
*/ |
|
168
|
|
|
protected function addMessages($messages, $index = null) |
|
169
|
|
|
{ |
|
170
|
|
|
if ($index === null) { |
|
171
|
|
|
$this->messages = array_merge($this->messages, $messages); |
|
172
|
|
|
} else { |
|
173
|
|
|
foreach ($messages as $message) { |
|
174
|
|
|
$this->messages[$index][] = $message; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @param State $state |
|
182
|
|
|
* @param string $category |
|
183
|
|
|
* @param string $subject |
|
184
|
|
|
* @param string $message |
|
185
|
|
|
* |
|
186
|
|
|
* @return void |
|
187
|
|
|
*/ |
|
188
|
|
|
protected function addMessage($state, $category, $subject, $message) |
|
189
|
|
|
{ |
|
190
|
|
|
assert(($state instanceof State) && is_string($category) && is_string($subject) && is_string($message)); |
|
191
|
|
|
$this->messages[] = array($state, $category, $subject, $message); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param mixed $value |
|
197
|
|
|
* @param string|null $index |
|
198
|
|
|
* |
|
199
|
|
|
* @return void |
|
200
|
|
|
*/ |
|
201
|
|
|
protected function addOutput($value, $index = null) |
|
202
|
|
|
{ |
|
203
|
|
|
if ($index === null) { |
|
204
|
|
|
$this->output = array_merge($this->output, $value); |
|
205
|
|
|
} else { |
|
206
|
|
|
$this->output[$index] = $value; |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return void |
|
213
|
|
|
*/ |
|
214
|
|
|
protected function setOutput($output) |
|
215
|
|
|
{ |
|
216
|
|
|
assert(is_array($output)); |
|
217
|
|
|
$this->output = $output; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* @return void |
|
223
|
|
|
*/ |
|
224
|
|
|
protected function setState($state) |
|
225
|
|
|
{ |
|
226
|
|
|
assert($state instanceof State); |
|
227
|
|
|
$this->state = $state; |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..