|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace whm\Smoke\Rules\Cookies; |
|
4
|
|
|
|
|
5
|
|
|
use phm\HttpWebdriverClient\Http\Response\CookieAwareResponse; |
|
6
|
|
|
use phm\HttpWebdriverClient\Http\Response\TimeoutAwareResponse; |
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use whm\Smoke\Rules\Attribute; |
|
9
|
|
|
use whm\Smoke\Rules\CheckResult; |
|
10
|
|
|
use whm\Smoke\Rules\Rule; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This rule can validate if a http request takes longer than a given max duration. |
|
14
|
|
|
* A website that is slower than one second is considered as slow. |
|
15
|
|
|
*/ |
|
16
|
|
|
class CountRule implements Rule |
|
17
|
|
|
{ |
|
18
|
|
|
private $maxCookies; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param int $maxDuration The maximum duration a http call is allowed to take (time to first byte) |
|
|
|
|
|
|
22
|
|
|
*/ |
|
23
|
|
|
public function init($maxElements = 20) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->maxCookies = $maxElements; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function validate(ResponseInterface $response) |
|
29
|
|
|
{ |
|
30
|
|
|
if ($response instanceof CookieAwareResponse) { |
|
31
|
|
|
|
|
32
|
|
|
if (!$response instanceof TimeoutAwareResponse || !$response->isTimeout()) { |
|
33
|
|
|
|
|
34
|
|
|
$cookieCount = $response->getCookieCount(); |
|
35
|
|
|
|
|
36
|
|
|
if ($cookieCount > $this->maxCookies) { |
|
37
|
|
|
$result = new CheckResult( |
|
38
|
|
|
CheckResult::STATUS_FAILURE, |
|
39
|
|
|
$cookieCount . ' cookies were stored (limit was ' . $this->maxCookies . ').', |
|
40
|
|
|
$cookieCount); |
|
41
|
|
|
} else { |
|
42
|
|
|
$result = new CheckResult( |
|
43
|
|
|
CheckResult::STATUS_SUCCESS, |
|
44
|
|
|
$cookieCount . ' cookies were stored (limit was ' . $this->maxCookies . ').', |
|
45
|
|
|
$cookieCount); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$cookies = $response->getCookies(); |
|
49
|
|
|
|
|
50
|
|
|
$result->addAttribute(new Attribute('cookies', json_encode($cookies), true)); |
|
51
|
|
|
|
|
52
|
|
|
return $result; |
|
53
|
|
|
} else { |
|
54
|
|
|
$result = new CheckResult( |
|
55
|
|
|
CheckResult::STATUS_SKIPPED, |
|
56
|
|
|
'Skipped: Request timed out. Cannot read cookies.', |
|
57
|
|
|
0); |
|
58
|
|
|
|
|
59
|
|
|
return $result; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.