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