@@ -55,19 +55,20 @@ abstract class AbstractMetricCheck
55
55
protected $ logger ;
56
56
57
57
/**
58
- * @var bool
58
+ * @var boolean
59
59
*/
60
60
protected $ verbose ;
61
61
62
62
/**
63
63
* Constructor, called from the beforeTest event
64
64
*
65
65
* @param PageReadinessExtension $extension
66
- * @param TestInterface $test
67
- * @param integer $resetFailureThreshold
66
+ * @param TestInterface $test
67
+ * @param integer $resetFailureThreshold
68
68
* @throws \Exception
69
69
*/
70
- public function __construct ($ extension , $ test , $ resetFailureThreshold ){
70
+ public function __construct ($ extension , $ test , $ resetFailureThreshold )
71
+ {
71
72
$ this ->extension = $ extension ;
72
73
$ this ->test = $ test ;
73
74
$ this ->logger = LoggingUtil::getInstance ()->getLogger (get_class ($ this ));
@@ -78,8 +79,7 @@ public function __construct($extension, $test, $resetFailureThreshold){
78
79
$ reflector = new \ReflectionMethod ($ this , 'clearFailureOnPage ' );
79
80
if ($ reflector ->getDeclaringClass ()->getName () === get_class ($ this )) {
80
81
$ this ->resetFailureThreshold = $ resetFailureThreshold ;
81
- }
82
- else {
82
+ } else {
83
83
$ this ->resetFailureThreshold = -1 ;
84
84
}
85
85
@@ -90,25 +90,26 @@ public function __construct($extension, $test, $resetFailureThreshold){
90
90
* Does the given value pass the readiness metric
91
91
*
92
92
* @param mixed $value
93
- * @return bool
93
+ * @return boolean
94
94
*/
95
- protected abstract function doesMetricPass ($ value );
95
+ abstract protected function doesMetricPass ($ value );
96
96
97
97
/**
98
98
* Retrieve the active value for the metric to check from the page
99
99
*
100
100
* @return mixed
101
101
* @throws UnexpectedAlertOpenException
102
102
*/
103
- protected abstract function fetchValueFromPage ();
103
+ abstract protected function fetchValueFromPage ();
104
104
105
105
/**
106
106
* Override this method to reset the actual state of the page to make the metric pass
107
107
* This method is called when too many identical failures were encountered in a row
108
108
*
109
109
* @return void
110
110
*/
111
- protected function clearFailureOnPage () {
111
+ protected function clearFailureOnPage ()
112
+ {
112
113
return ;
113
114
}
114
115
@@ -117,7 +118,8 @@ protected function clearFailureOnPage() {
117
118
*
118
119
* @return string
119
120
*/
120
- public function getName () {
121
+ public function getName ()
122
+ {
121
123
$ clazz = get_class ($ this );
122
124
$ namespaceBreak = strrpos ($ clazz , '\\' );
123
125
if ($ namespaceBreak !== false ) {
@@ -133,10 +135,11 @@ public function getName() {
133
135
* to catch cases where a slow request of one metric can trigger calls for other metrics that were previously
134
136
* thought ready
135
137
*
136
- * @return bool
138
+ * @return boolean
137
139
* @throws UnexpectedAlertOpenException
138
140
*/
139
- public function runCheck () {
141
+ public function runCheck ()
142
+ {
140
143
if ($ this ->doesMetricPass ($ this ->getCurrentValue (true ))) {
141
144
$ this ->setTracker ($ this ->getCurrentValue ());
142
145
return true ;
@@ -154,11 +157,11 @@ public function runCheck() {
154
157
* @param Step $step
155
158
* @return void
156
159
*/
157
- public function finalize ($ step ) {
160
+ public function finalize ($ step )
161
+ {
158
162
try {
159
163
$ currentValue = $ this ->getCurrentValue ();
160
- }
161
- catch (UnexpectedAlertOpenException $ exception ) {
164
+ } catch (UnexpectedAlertOpenException $ exception ) {
162
165
$ this ->debugLog (
163
166
'An alert is open, bypassing javascript-based metric check ' ,
164
167
['action ' => $ step ->getAction ()]
@@ -168,13 +171,11 @@ public function finalize($step) {
168
171
169
172
if ($ this ->doesMetricPass ($ currentValue )) {
170
173
$ this ->setTracker ($ currentValue );
171
- }
172
- else {
174
+ } else {
173
175
// If failure happened on the same value as before, increment the fail count, otherwise set at 1
174
176
if ($ currentValue !== $ this ->getStoredValue ()) {
175
177
$ failCount = 1 ;
176
- }
177
- else {
178
+ } else {
178
179
$ failCount = $ this ->getFailureCount () + 1 ;
179
180
}
180
181
$ this ->setTracker ($ currentValue , $ failCount );
@@ -197,32 +198,35 @@ public function finalize($step) {
197
198
* @return WebDriver
198
199
* @throws ModuleRequireException
199
200
*/
200
- protected function getDriver () {
201
+ protected function getDriver ()
202
+ {
201
203
return $ this ->extension ->getDriver ();
202
204
}
203
205
204
206
/**
205
207
* Helper function to execute javascript code, see WebDriver::executeJs for more information
206
208
*
207
209
* @param string $script
208
- * @param array $arguments
210
+ * @param array $arguments
209
211
* @return mixed
210
212
* @throws UnexpectedAlertOpenException
211
213
* @throws ModuleRequireException
212
214
*/
213
- protected function executeJs ($ script , $ arguments = []) {
215
+ protected function executeJs ($ script , $ arguments = [])
216
+ {
214
217
return $ this ->getDriver ()->executeJS ($ script , $ arguments );
215
218
}
216
219
217
220
/**
218
221
* Gets the current state of the given variable
219
222
* Fetches an updated value if not known or $refresh is true
220
223
*
221
- * @param bool $refresh
224
+ * @param boolean $refresh
222
225
* @return mixed
223
226
* @throws UnexpectedAlertOpenException
224
227
*/
225
- private function getCurrentValue ($ refresh = false ) {
228
+ private function getCurrentValue ($ refresh = false )
229
+ {
226
230
if ($ refresh ) {
227
231
unset($ this ->currentValue );
228
232
}
@@ -237,17 +241,19 @@ private function getCurrentValue($refresh = false) {
237
241
*
238
242
* @return mixed
239
243
*/
240
- public function getStoredValue () {
244
+ public function getStoredValue ()
245
+ {
241
246
return $ this ->test ->getMetadata ()->getCurrent ($ this ->getName ());
242
247
}
243
248
244
249
/**
245
250
* The current count of sequential identical failures
246
251
* Used to detect potentially stuck metrics
247
252
*
248
- * @return int
253
+ * @return integer
249
254
*/
250
- public function getFailureCount () {
255
+ public function getFailureCount ()
256
+ {
251
257
return $ this ->test ->getMetadata ()->getCurrent ($ this ->getName () . '.failCount ' );
252
258
}
253
259
@@ -257,33 +263,37 @@ public function getFailureCount() {
257
263
*
258
264
* @return void
259
265
*/
260
- private function resetMetric () {
266
+ private function resetMetric ()
267
+ {
261
268
$ this ->clearFailureOnPage ();
262
269
$ this ->setTracker ();
263
270
}
264
271
265
272
/**
266
273
* Tracks the most recent value and the number of identical failures in a row
267
274
*
268
- * @param mixed $value
269
- * @param int $failCount
275
+ * @param mixed $value
276
+ * @param integer $failCount
270
277
* @return void
271
278
*/
272
- public function setTracker ($ value = null , $ failCount = 0 ) {
279
+ public function setTracker ($ value = null , $ failCount = 0 )
280
+ {
273
281
$ this ->test ->getMetadata ()->setCurrent ([
274
282
$ this ->getName () => $ value ,
275
283
$ this ->getName () . '.failCount ' => $ failCount
276
284
]);
277
- unset ($ this ->currentValue );
285
+ unset($ this ->currentValue );
278
286
}
279
287
280
288
/**
281
289
* Log the given message to logger->error including context information
282
290
*
283
291
* @param string $message
284
- * @param array $context
292
+ * @param array $context
293
+ * @return void
285
294
*/
286
- protected function errorLog ($ message , $ context = []) {
295
+ protected function errorLog ($ message , $ context = [])
296
+ {
287
297
$ context = array_merge ($ this ->getLogContext (), $ context );
288
298
$ this ->logger ->error ($ message , $ context );
289
299
}
@@ -292,9 +302,11 @@ protected function errorLog($message, $context = []) {
292
302
* Log the given message to logger->info including context information
293
303
*
294
304
* @param string $message
295
- * @param array $context
305
+ * @param array $context
306
+ * @return void
296
307
*/
297
- protected function infoLog ($ message , $ context = []) {
308
+ protected function infoLog ($ message , $ context = [])
309
+ {
298
310
$ context = array_merge ($ this ->getLogContext (), $ context );
299
311
$ this ->logger ->info ($ message , $ context );
300
312
}
@@ -303,9 +315,11 @@ protected function infoLog($message, $context = []) {
303
315
* If verbose, log the given message to logger->debug including context information
304
316
*
305
317
* @param string $message
306
- * @param array $context
318
+ * @param array $context
319
+ * @return void
307
320
*/
308
- protected function debugLog ($ message , $ context = []) {
321
+ protected function debugLog ($ message , $ context = [])
322
+ {
309
323
if ($ this ->verbose ) {
310
324
$ context = array_merge ($ this ->getLogContext (), $ context );
311
325
$ this ->logger ->debug ($ message , $ context );
@@ -318,7 +332,8 @@ protected function debugLog($message, $context = []) {
318
332
*
319
333
* @return array
320
334
*/
321
- private function getLogContext () {
335
+ private function getLogContext ()
336
+ {
322
337
$ testMeta = $ this ->test ->getMetadata ();
323
338
return [
324
339
'test ' => $ testMeta ->getName (),
0 commit comments