3
3
namespace Http \Mock ;
4
4
5
5
use Http \Client \Common \HttpAsyncClientEmulator ;
6
- use Http \Client \Common \VersionBridgeClient ;
7
6
use Http \Client \Exception ;
8
7
use Http \Client \HttpAsyncClient ;
9
8
use Http \Client \HttpClient ;
23
22
class Client implements HttpClient, HttpAsyncClient
24
23
{
25
24
use HttpAsyncClientEmulator;
26
- use VersionBridgeClient;
27
25
28
26
/**
29
27
* @var ResponseFactory
@@ -61,9 +59,15 @@ public function __construct(ResponseFactory $responseFactory = null)
61
59
}
62
60
63
61
/**
64
- * {@inheritdoc}
62
+ * This will in order:
63
+ *
64
+ * - Throw the next exception in the list and advance
65
+ * - Return the next response in the list and advance
66
+ * - Throw the default exception if set (forever)
67
+ * - Return the default response if set (forever)
68
+ * - Create a new empty response with the response factory
65
69
*/
66
- public function doSendRequest (RequestInterface $ request )
70
+ public function sendRequest (RequestInterface $ request ): ResponseInterface
67
71
{
68
72
$ this ->requests [] = $ request ;
69
73
@@ -100,7 +104,7 @@ public function addException(\Exception $exception)
100
104
*
101
105
* If both a default exception and a default response are set, the exception will be thrown.
102
106
*/
103
- public function setDefaultException (\Exception $ defaultException = null )
107
+ public function setDefaultException (? \Exception $ defaultException )
104
108
{
105
109
$ this ->defaultException = $ defaultException ;
106
110
}
@@ -116,7 +120,7 @@ public function addResponse(ResponseInterface $response)
116
120
/**
117
121
* Sets the default response to be returned when the list of added exceptions and responses is exhausted.
118
122
*/
119
- public function setDefaultResponse (ResponseInterface $ defaultResponse = null )
123
+ public function setDefaultResponse (? ResponseInterface $ defaultResponse )
120
124
{
121
125
$ this ->defaultResponse = $ defaultResponse ;
122
126
}
@@ -126,13 +130,13 @@ public function setDefaultResponse(ResponseInterface $defaultResponse = null)
126
130
*
127
131
* @return RequestInterface[]
128
132
*/
129
- public function getRequests ()
133
+ public function getRequests (): array
130
134
{
131
135
return $ this ->requests ;
132
136
}
133
137
134
- public function getLastRequest ()
138
+ public function getLastRequest (): ? RequestInterface
135
139
{
136
- return end ($ this ->requests );
140
+ return end ($ this ->requests ) ?: null ;
137
141
}
138
142
}
0 commit comments