33namespace Http \Mock ;
44
55use Http \Client \Common \HttpAsyncClientEmulator ;
6+ use Http \Client \Common \VersionBridgeClient ;
67use Http \Client \Exception ;
78use Http \Client \HttpAsyncClient ;
89use Http \Client \HttpClient ;
1213use Psr \Http \Message \ResponseInterface ;
1314
1415/**
15- * HTTP client mock .
16+ * An implementation of the HTTP client that is useful for automated tests .
1617 *
17- * This mock is most useful in tests. It does not send requests but stores them
18- * for later retrieval. Additionally, you can set an exception to test
19- * exception handling.
18+ * This mock does not send requests but stores them for later retrieval.
19+ * You can configure the mock with responses to return and/or exceptions to throw.
2020 *
2121 * @author David de Boer <david@ddeboer.nl>
2222 */
2323class Client implements HttpClient, HttpAsyncClient
2424{
2525 use HttpAsyncClientEmulator;
26+ use VersionBridgeClient;
2627
2728 /**
2829 * @var ResponseFactory
@@ -54,9 +55,6 @@ class Client implements HttpClient, HttpAsyncClient
5455 */
5556 private $ defaultException ;
5657
57- /**
58- * @param ResponseFactory|null $responseFactory
59- */
6058 public function __construct (ResponseFactory $ responseFactory = null )
6159 {
6260 $ this ->responseFactory = $ responseFactory ?: MessageFactoryDiscovery::find ();
@@ -65,7 +63,7 @@ public function __construct(ResponseFactory $responseFactory = null)
6563 /**
6664 * {@inheritdoc}
6765 */
68- public function sendRequest (RequestInterface $ request )
66+ public function doSendRequest (RequestInterface $ request )
6967 {
7068 $ this ->requests [] = $ request ;
7169
@@ -91,8 +89,6 @@ public function sendRequest(RequestInterface $request)
9189
9290 /**
9391 * Adds an exception that will be thrown.
94- *
95- * @param \Exception $exception
9692 */
9793 public function addException (\Exception $ exception )
9894 {
@@ -103,18 +99,14 @@ public function addException(\Exception $exception)
10399 * Sets the default exception to throw when the list of added exceptions and responses is exhausted.
104100 *
105101 * If both a default exception and a default response are set, the exception will be thrown.
106- *
107- * @param \Exception|null $defaultException
108102 */
109103 public function setDefaultException (\Exception $ defaultException = null )
110104 {
111105 $ this ->defaultException = $ defaultException ;
112106 }
113107
114108 /**
115- * Adds a response that will be returned.
116- *
117- * @param ResponseInterface $response
109+ * Adds a response that will be returned in first in first out order.
118110 */
119111 public function addResponse (ResponseInterface $ response )
120112 {
@@ -123,8 +115,6 @@ public function addResponse(ResponseInterface $response)
123115
124116 /**
125117 * Sets the default response to be returned when the list of added exceptions and responses is exhausted.
126- *
127- * @param ResponseInterface|null $defaultResponse
128118 */
129119 public function setDefaultResponse (ResponseInterface $ defaultResponse = null )
130120 {
@@ -141,9 +131,6 @@ public function getRequests()
141131 return $ this ->requests ;
142132 }
143133
144- /**
145- * @return RequestInterface|false
146- */
147134 public function getLastRequest ()
148135 {
149136 return end ($ this ->requests );
0 commit comments