1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor; |
4
|
|
|
|
5
|
|
|
final class TestResult |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var string Test category this test belongs to |
9
|
|
|
*/ |
10
|
|
|
private $category; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string The subject that was tested |
14
|
|
|
*/ |
15
|
|
|
private $subject; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string Message describing the result |
19
|
|
|
*/ |
20
|
|
|
private $message; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array Data to be used by TestSuite or other TestCases |
24
|
|
|
*/ |
25
|
|
|
private $output; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var State The State object reflecting the result |
29
|
|
|
*/ |
30
|
|
|
private $state = State::NOSTATE; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $category |
35
|
|
|
* @param string $subject |
36
|
|
|
*/ |
37
|
|
|
public function __construct($category = 'Unknown category', $subject = 'Unknown subject') |
38
|
|
|
{ |
39
|
|
|
$this->setCategory($category); |
40
|
|
|
$this->setSubject($subject); |
41
|
|
|
$this->setOutput(array()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $subject |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function setSubject($subject) |
51
|
|
|
{ |
52
|
|
|
assert(is_string($subject)); |
53
|
|
|
$this->subject = $subject; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getSubject() |
61
|
|
|
{ |
62
|
|
|
assert(is_string($this->subject)); |
63
|
|
|
return $this->subject; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $category |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function setCategory($category) |
73
|
|
|
{ |
74
|
|
|
assert(is_string($category)); |
75
|
|
|
$this->category = $category; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getCategory() |
83
|
|
|
{ |
84
|
|
|
assert(is_string($this->category)); |
85
|
|
|
return $this->category; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $message |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
public function setMessage($message) |
95
|
|
|
{ |
96
|
|
|
assert(is_string($message)); |
97
|
|
|
$this->message = $message; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function getMessage() |
105
|
|
|
{ |
106
|
|
|
assert(is_string($this->message)); |
107
|
|
|
return $this->message; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $value |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function setOutput($value) |
117
|
|
|
{ |
118
|
|
|
assert(is_array($value)); |
119
|
|
|
$this->output = $value; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param mixed $value |
125
|
|
|
* @param string|null $index |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
protected function addOutput($value, $index = null) |
130
|
|
|
{ |
131
|
|
|
if ($index === null) { |
132
|
|
|
$this->output = array_merge($this->output, $value); |
133
|
|
|
} else { |
134
|
|
|
$this->output[$index] = $value; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string|null $key |
141
|
|
|
* |
142
|
|
|
* @return mixed |
143
|
|
|
*/ |
144
|
|
|
public function getOutput($key = null) |
145
|
|
|
{ |
146
|
|
|
assert(is_array($this->output)); |
147
|
|
|
return is_null($key) ? $this->output : (isSet($this->output[$key]) ? $this->output[$key] : null); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param State $state |
153
|
|
|
* |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
|
public function setState($state = State::NOSTATE) |
157
|
|
|
{ |
158
|
|
|
assert($state instanceof State); |
159
|
|
|
$this->state = $state; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return State |
165
|
|
|
*/ |
166
|
|
|
public function getState() |
167
|
|
|
{ |
168
|
|
|
assert($this->state instanceof State); |
169
|
|
|
return $this->state; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|