1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Scientist; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Execution |
9
|
|
|
* |
10
|
|
|
* An execution records the state of a callback, including how long it |
11
|
|
|
* took to execute, and what values were returned. |
12
|
|
|
* |
13
|
|
|
* @package \Scientist |
14
|
|
|
*/ |
15
|
|
|
class Result |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Callback result value. |
19
|
|
|
* |
20
|
|
|
* @var mixed |
21
|
|
|
*/ |
22
|
|
|
protected $value; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The time the callback was executed. |
26
|
|
|
* |
27
|
|
|
* @var float |
28
|
|
|
*/ |
29
|
|
|
protected $startTime; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The time the callback finished executing. |
33
|
|
|
* |
34
|
|
|
* @var float |
35
|
|
|
*/ |
36
|
|
|
protected $endTime; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The memory usage before the callback is executed. |
40
|
|
|
* |
41
|
|
|
* @var float |
42
|
|
|
*/ |
43
|
|
|
protected $startMemory; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The memory usage after the callback is executed. |
47
|
|
|
* |
48
|
|
|
* @var float |
49
|
|
|
*/ |
50
|
|
|
protected $endMemory; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Exception thrown by callback. |
54
|
|
|
* |
55
|
|
|
* @var \Exception|null |
56
|
|
|
*/ |
57
|
|
|
protected $exception; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Does the callback result value match the control. |
61
|
|
|
* |
62
|
|
|
* @var boolean |
63
|
|
|
*/ |
64
|
|
|
protected $match = false; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the callback result value. |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
8 |
|
public function getValue() |
72
|
|
|
{ |
73
|
8 |
|
return $this->value; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Set the callback result value. |
78
|
|
|
* |
79
|
|
|
* @param mixed $value |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
11 |
|
public function setValue($value) |
84
|
|
|
{ |
85
|
11 |
|
$this->value = $value; |
86
|
|
|
|
87
|
11 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the callback execution start time. |
92
|
|
|
* |
93
|
|
|
* @return float |
94
|
|
|
*/ |
95
|
2 |
|
public function getStartTime() |
96
|
|
|
{ |
97
|
2 |
|
return $this->startTime; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set the callback execution start time. |
102
|
|
|
* |
103
|
|
|
* @param float $startTime |
104
|
|
|
* |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
13 |
|
public function setStartTime($startTime) |
108
|
|
|
{ |
109
|
13 |
|
$this->startTime = $startTime; |
110
|
|
|
|
111
|
13 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the callback execution end time. |
116
|
|
|
* |
117
|
|
|
* @return float |
118
|
|
|
*/ |
119
|
2 |
|
public function getEndTime() |
120
|
|
|
{ |
121
|
2 |
|
return $this->endTime; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set the callback execution end time. |
126
|
|
|
* |
127
|
|
|
* @param float $endTime |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
12 |
|
public function setEndTime($endTime) |
132
|
|
|
{ |
133
|
12 |
|
$this->endTime = $endTime; |
134
|
|
|
|
135
|
12 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the execution time of the callback. |
140
|
|
|
* |
141
|
|
|
* @return float |
142
|
|
|
*/ |
143
|
2 |
|
public function getTime() |
144
|
|
|
{ |
145
|
2 |
|
return $this->endTime - $this->startTime; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get the callback execution starting memory usage. |
150
|
|
|
* |
151
|
|
|
* @return float |
152
|
|
|
*/ |
153
|
2 |
|
public function getStartMemory() |
154
|
|
|
{ |
155
|
2 |
|
return $this->startMemory; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Set the callback execution starting memory usage. |
160
|
|
|
* |
161
|
|
|
* @param float $startMemory |
162
|
|
|
* |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
13 |
|
public function setStartMemory($startMemory) |
166
|
|
|
{ |
167
|
13 |
|
$this->startMemory = $startMemory; |
168
|
|
|
|
169
|
13 |
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get the callback execution ending memory usage. |
174
|
|
|
* |
175
|
|
|
* @return float |
176
|
|
|
*/ |
177
|
2 |
|
public function getEndMemory() |
178
|
|
|
{ |
179
|
2 |
|
return $this->endMemory; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Set the callback execution ending memory usage. |
184
|
|
|
* |
185
|
|
|
* @param float $endMemory |
186
|
|
|
* |
187
|
|
|
* @return $this |
188
|
|
|
*/ |
189
|
12 |
|
public function setEndMemory($endMemory) |
190
|
|
|
{ |
191
|
12 |
|
$this->endMemory = $endMemory; |
192
|
|
|
|
193
|
12 |
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Get the memory spike amount of the callback. |
198
|
|
|
* |
199
|
|
|
* @return float |
200
|
|
|
*/ |
201
|
1 |
|
public function getMemory() |
202
|
|
|
{ |
203
|
1 |
|
return $this->endMemory - $this->startMemory; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get the exception thrown by the callback. |
208
|
|
|
* |
209
|
|
|
* @return Exception|null |
210
|
|
|
*/ |
211
|
1 |
|
public function getException() |
212
|
|
|
{ |
213
|
1 |
|
return $this->exception; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Set the exception thrown by the callback. |
218
|
|
|
* |
219
|
|
|
* @param Exception|null $exception |
220
|
|
|
* |
221
|
|
|
* @return $this |
222
|
|
|
*/ |
223
|
2 |
|
public function setException($exception) |
224
|
|
|
{ |
225
|
2 |
|
$this->exception = $exception; |
226
|
|
|
|
227
|
2 |
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Determine whether the callback result matches the control. |
232
|
|
|
* |
233
|
|
|
* @return boolean |
234
|
|
|
*/ |
235
|
3 |
|
public function isMatch() |
236
|
|
|
{ |
237
|
3 |
|
return $this->match; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Set whether the callback result matches the control. |
242
|
|
|
* |
243
|
|
|
* @param boolean $match |
244
|
|
|
* |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
3 |
|
public function setMatch($match) |
248
|
|
|
{ |
249
|
3 |
|
$this->match = $match; |
250
|
|
|
|
251
|
3 |
|
return $this; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|