|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Psr7Unitesting; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\Http\Message\RequestInterface; |
|
6
|
|
|
use Psr\Http\Message\UriInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class to execute assertions in a RequestInstance message. |
|
10
|
|
|
*/ |
|
11
|
|
|
class Request extends Message |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var RequestInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $message; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param RequestInterface $message |
|
22
|
|
|
* @param AbstractAssert|null $previous |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(RequestInterface $message, Utils\AbstractAssert $previous = null) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($message, $previous); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Asserts the method of the request. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $method |
|
33
|
|
|
* @param string $message |
|
34
|
|
|
* |
|
35
|
|
|
* @return self |
|
36
|
|
|
*/ |
|
37
|
|
|
public function method($method, $message = '') |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->assert($this->message, new Request\Method($method), $message); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Asserts the request target of the request. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $requestTarget |
|
46
|
|
|
* @param string $message |
|
47
|
|
|
* |
|
48
|
|
|
* @return self |
|
49
|
|
|
*/ |
|
50
|
|
|
public function requestTarget($requestTarget, $message = '') |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->assert($this->message, new Request\RequestTarget($requestTarget), $message); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Asserts the uri value. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string|UriInterface $uri |
|
59
|
|
|
* @param string $message |
|
60
|
|
|
* |
|
61
|
|
|
* @return self |
|
62
|
|
|
*/ |
|
63
|
|
|
public function uri($uri, $message = '') |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->assert($this->message, new Request\Uri((string) $uri), $message); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Creates an Uri instance to execute assertions with the UriInterface. |
|
70
|
|
|
* |
|
71
|
|
|
* @return Uri |
|
72
|
|
|
*/ |
|
73
|
|
|
public function assertUri() |
|
74
|
|
|
{ |
|
75
|
|
|
return new Uri($this->message->getUri(), $this); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|