3
3
namespace Http \Mock ;
4
4
5
5
use Http \Client \Common \HttpAsyncClientEmulator ;
6
+ use Http \Client \Common \VersionBridgeClient ;
6
7
use Http \Client \Exception ;
7
8
use Http \Client \HttpAsyncClient ;
8
9
use Http \Client \HttpClient ;
12
13
use Psr \Http \Message \ResponseInterface ;
13
14
14
15
/**
15
- * HTTP client mock .
16
+ * An implementation of the HTTP client that is useful for automated tests .
16
17
*
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.
20
20
*
21
21
* @author David de Boer <[email protected] >
22
22
*/
23
23
class Client implements HttpClient, HttpAsyncClient
24
24
{
25
25
use HttpAsyncClientEmulator;
26
+ use VersionBridgeClient;
26
27
27
28
/**
28
29
* @var ResponseFactory
@@ -54,9 +55,6 @@ class Client implements HttpClient, HttpAsyncClient
54
55
*/
55
56
private $ defaultException ;
56
57
57
- /**
58
- * @param ResponseFactory|null $responseFactory
59
- */
60
58
public function __construct (ResponseFactory $ responseFactory = null )
61
59
{
62
60
$ this ->responseFactory = $ responseFactory ?: MessageFactoryDiscovery::find ();
@@ -65,7 +63,7 @@ public function __construct(ResponseFactory $responseFactory = null)
65
63
/**
66
64
* {@inheritdoc}
67
65
*/
68
- public function sendRequest (RequestInterface $ request )
66
+ public function doSendRequest (RequestInterface $ request )
69
67
{
70
68
$ this ->requests [] = $ request ;
71
69
@@ -91,8 +89,6 @@ public function sendRequest(RequestInterface $request)
91
89
92
90
/**
93
91
* Adds an exception that will be thrown.
94
- *
95
- * @param \Exception $exception
96
92
*/
97
93
public function addException (\Exception $ exception )
98
94
{
@@ -103,18 +99,14 @@ public function addException(\Exception $exception)
103
99
* Sets the default exception to throw when the list of added exceptions and responses is exhausted.
104
100
*
105
101
* If both a default exception and a default response are set, the exception will be thrown.
106
- *
107
- * @param \Exception|null $defaultException
108
102
*/
109
103
public function setDefaultException (\Exception $ defaultException = null )
110
104
{
111
105
$ this ->defaultException = $ defaultException ;
112
106
}
113
107
114
108
/**
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.
118
110
*/
119
111
public function addResponse (ResponseInterface $ response )
120
112
{
@@ -123,8 +115,6 @@ public function addResponse(ResponseInterface $response)
123
115
124
116
/**
125
117
* Sets the default response to be returned when the list of added exceptions and responses is exhausted.
126
- *
127
- * @param ResponseInterface|null $defaultResponse
128
118
*/
129
119
public function setDefaultResponse (ResponseInterface $ defaultResponse = null )
130
120
{
@@ -141,9 +131,6 @@ public function getRequests()
141
131
return $ this ->requests ;
142
132
}
143
133
144
- /**
145
- * @return RequestInterface|false
146
- */
147
134
public function getLastRequest ()
148
135
{
149
136
return end ($ this ->requests );
0 commit comments