33namespace Http \Mock ;
44
55use Http \Client \Common \HttpAsyncClientEmulator ;
6- use Http \Client \Common \VersionBridgeClient ;
76use Http \Client \Exception ;
87use Http \Client \HttpAsyncClient ;
98use Http \Client \HttpClient ;
2322class Client implements HttpClient, HttpAsyncClient
2423{
2524 use HttpAsyncClientEmulator;
26- use VersionBridgeClient;
2725
2826 /**
2927 * @var ResponseFactory
@@ -61,9 +59,15 @@ public function __construct(ResponseFactory $responseFactory = null)
6159 }
6260
6361 /**
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
6569 */
66- public function doSendRequest (RequestInterface $ request )
70+ public function sendRequest (RequestInterface $ request ): ResponseInterface
6771 {
6872 $ this ->requests [] = $ request ;
6973
@@ -100,7 +104,7 @@ public function addException(\Exception $exception)
100104 *
101105 * If both a default exception and a default response are set, the exception will be thrown.
102106 */
103- public function setDefaultException (\Exception $ defaultException = null )
107+ public function setDefaultException (? \Exception $ defaultException )
104108 {
105109 $ this ->defaultException = $ defaultException ;
106110 }
@@ -116,7 +120,7 @@ public function addResponse(ResponseInterface $response)
116120 /**
117121 * Sets the default response to be returned when the list of added exceptions and responses is exhausted.
118122 */
119- public function setDefaultResponse (ResponseInterface $ defaultResponse = null )
123+ public function setDefaultResponse (? ResponseInterface $ defaultResponse )
120124 {
121125 $ this ->defaultResponse = $ defaultResponse ;
122126 }
@@ -126,13 +130,13 @@ public function setDefaultResponse(ResponseInterface $defaultResponse = null)
126130 *
127131 * @return RequestInterface[]
128132 */
129- public function getRequests ()
133+ public function getRequests (): array
130134 {
131135 return $ this ->requests ;
132136 }
133137
134- public function getLastRequest ()
138+ public function getLastRequest (): ? RequestInterface
135139 {
136- return end ($ this ->requests );
140+ return end ($ this ->requests ) ?: null ;
137141 }
138142}
0 commit comments