1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psr7Unitesting; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class to execute assertions in a ServerRequestInstance message. |
9
|
|
|
*/ |
10
|
|
|
class ServerRequest extends Request |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var ServerRequestInterface |
14
|
|
|
*/ |
15
|
|
|
protected $message; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Constructor. |
19
|
|
|
* |
20
|
|
|
* @param ServerRequestInterface $message |
21
|
|
|
* @param AbstractAssert|null $previous |
22
|
|
|
*/ |
23
|
|
|
public function __construct(ServerRequestInterface $message, Utils\AbstractAssert $previous = null) |
24
|
|
|
{ |
25
|
|
|
parent::__construct($message, $previous); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Check if the server params contains a key. |
30
|
|
|
* |
31
|
|
|
* @param string $key |
32
|
|
|
* @param string $message |
33
|
|
|
* |
34
|
|
|
* @return self |
35
|
|
|
*/ |
36
|
|
|
public function hasServerParam($key, $message = '') |
37
|
|
|
{ |
38
|
|
|
return $this->assert($this->message, new ServerRequest\HasServerParam($key), $message); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Asserts a server param. |
43
|
|
|
* |
44
|
|
|
* @param string $key |
45
|
|
|
* @param string $value |
46
|
|
|
* @param string $message |
47
|
|
|
* |
48
|
|
|
* @return self |
49
|
|
|
*/ |
50
|
|
|
public function serverParam($key, $value, $message = '') |
51
|
|
|
{ |
52
|
|
|
return $this->assert($this->message, new ServerRequest\ServerParam($key, $value), $message); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Check if the cookie params contains a key. |
57
|
|
|
* |
58
|
|
|
* @param string $key |
59
|
|
|
* @param string $message |
60
|
|
|
* |
61
|
|
|
* @return self |
62
|
|
|
*/ |
63
|
|
|
public function hasCookieParam($key, $message = '') |
64
|
|
|
{ |
65
|
|
|
return $this->assert($this->message, new ServerRequest\HasCookieParam($key), $message); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Asserts a cookie param. |
70
|
|
|
* |
71
|
|
|
* @param string $key |
72
|
|
|
* @param string $value |
73
|
|
|
* @param string $message |
74
|
|
|
* |
75
|
|
|
* @return self |
76
|
|
|
*/ |
77
|
|
|
public function cookieParam($key, $value, $message = '') |
78
|
|
|
{ |
79
|
|
|
return $this->assert($this->message, new ServerRequest\CookieParam($key, $value), $message); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Check if the query params contains a key. |
84
|
|
|
* |
85
|
|
|
* @param string $key |
86
|
|
|
* @param string $message |
87
|
|
|
* |
88
|
|
|
* @return self |
89
|
|
|
*/ |
90
|
|
|
public function hasQueryParam($key, $message = '') |
91
|
|
|
{ |
92
|
|
|
return $this->assert($this->message, new ServerRequest\HasQueryParam($key), $message); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Asserts a query param. |
97
|
|
|
* |
98
|
|
|
* @param string $key |
99
|
|
|
* @param string $value |
100
|
|
|
* @param string $message |
101
|
|
|
* |
102
|
|
|
* @return self |
103
|
|
|
*/ |
104
|
|
|
public function queryParam($key, $value, $message = '') |
105
|
|
|
{ |
106
|
|
|
return $this->assert($this->message, new ServerRequest\QueryParam($key, $value), $message); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Check if the uploadedFiles contains a key. |
111
|
|
|
* |
112
|
|
|
* @param string $key |
113
|
|
|
* @param string $message |
114
|
|
|
* |
115
|
|
|
* @return self |
116
|
|
|
*/ |
117
|
|
|
public function hasUploadedFile($key, $message = '') |
118
|
|
|
{ |
119
|
|
|
return $this->assert($this->message, new ServerRequest\HasUploadedFile($key), $message); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Check if the parsedBody params contains a key. |
124
|
|
|
* |
125
|
|
|
* @param string $key |
126
|
|
|
* @param string $message |
127
|
|
|
* |
128
|
|
|
* @return self |
129
|
|
|
*/ |
130
|
|
|
public function hasParsedBody($key, $message = '') |
131
|
|
|
{ |
132
|
|
|
return $this->assert($this->message, new ServerRequest\HasParsedBody($key), $message); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Asserts a parsedBody param. |
137
|
|
|
* |
138
|
|
|
* @param string $key |
139
|
|
|
* @param string $value |
140
|
|
|
* @param string $message |
141
|
|
|
* |
142
|
|
|
* @return self |
143
|
|
|
*/ |
144
|
|
|
public function parsedBody($key, $value, $message = '') |
145
|
|
|
{ |
146
|
|
|
return $this->assert($this->message, new ServerRequest\ParsedBody($key, $value), $message); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Check if the attributes contains a key. |
151
|
|
|
* |
152
|
|
|
* @param string $key |
153
|
|
|
* @param string $message |
154
|
|
|
* |
155
|
|
|
* @return self |
156
|
|
|
*/ |
157
|
|
|
public function hasAttribute($key, $message = '') |
158
|
|
|
{ |
159
|
|
|
return $this->assert($this->message, new ServerRequest\HasAttribute($key), $message); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Asserts an attribute. |
164
|
|
|
* |
165
|
|
|
* @param string $key |
166
|
|
|
* @param string $value |
167
|
|
|
* @param string $message |
168
|
|
|
* |
169
|
|
|
* @return self |
170
|
|
|
*/ |
171
|
|
|
public function attribute($key, $value, $message = '') |
172
|
|
|
{ |
173
|
|
|
return $this->assert($this->message, new ServerRequest\Attribute($key, $value), $message); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|