-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
ResponseTrait.php
78 lines (68 loc) · 1.97 KB
/
ResponseTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace DrevOps\BehatSteps;
/**
* Trait ResponseTrait.
*
* Response-related steps.
*
* @package DrevOps\BehatSteps
*/
trait ResponseTrait {
/**
* Assert that a response contains a header with specified name.
*
* @code
* Then response contains header "Connection"
* @endcode
*
* @Then response contains header :name
*/
public function responseAssertContainsHeader(string $name): void {
$header = $this->getSession()->getResponseHeader($name);
if (!$header) {
throw new \Exception(sprintf('Response does not contain header %s', $name));
}
}
/**
* Assert that a response does not contain a header with specified name.
*
* @code
* Then response does not contain header "Connection"
* @endcode
*
* @Then response does not contain header :name
*/
public function responseAssertNotContainsHeader(string $name): void {
$header = $this->getSession()->getResponseHeader($name);
if ($header) {
throw new \Exception(sprintf('Response contains header %s, but should not', $name));
}
}
/**
* Assert that a response contains a header with specified name and value.
*
* @code
* Then response header "Connection" contains "Keep-Alive"
* @endcode
*
* @Then response header :name contains :value
*/
public function responseAssertHeaderContains(string $name, string $value): void {
$this->responseAssertContainsHeader($name);
$this->assertSession()->responseHeaderContains($name, $value);
}
/**
* Assert a response does not contain a header with specified name and value.
*
* @code
* Then response header "Connection" does not contain "Keep-Alive"
* @endcode
*
* @Then response header :name does not contain :value
*/
public function responseAssertHeaderNotContains(string $name, string $value): void {
$this->responseAssertContainsHeader($name);
$this->assertSession()->responseHeaderNotContains($name, $value);
}
}