18
18
use Symfony \Component \HttpClient \Response \ResponseStream ;
19
19
use Symfony \Contracts \HttpClient \ChunkInterface ;
20
20
use Symfony \Contracts \HttpClient \HttpClientInterface ;
21
- use Symfony \Contracts \HttpClient \ResponseInterface ;
22
21
23
22
class MockHttpClientTest extends HttpClientTestCase
24
23
{
@@ -141,16 +140,8 @@ protected function getHttpClient(string $testCase): HttpClientInterface
141
140
break ;
142
141
143
142
case 'testDnsError ' :
144
- $ mock = $ this ->createMock (ResponseInterface::class);
145
- $ mock ->expects ($ this ->any ())
146
- ->method ('getStatusCode ' )
147
- ->willThrowException (new TransportException ('DSN error ' ));
148
- $ mock ->expects ($ this ->any ())
149
- ->method ('getInfo ' )
150
- ->willReturn ([]);
151
-
152
- $ responses [] = $ mock ;
153
- $ responses [] = $ mock ;
143
+ $ responses [] = $ mockResponse = new MockResponse ('' , ['error ' => 'DNS error ' ]);
144
+ $ responses [] = $ mockResponse ;
154
145
break ;
155
146
156
147
case 'testToStream ' :
@@ -164,12 +155,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
164
155
break ;
165
156
166
157
case 'testTimeoutOnAccess ' :
167
- $ mock = $ this ->createMock (ResponseInterface::class);
168
- $ mock ->expects ($ this ->any ())
169
- ->method ('getHeaders ' )
170
- ->willThrowException (new TransportException ('Timeout ' ));
171
-
172
- $ responses [] = $ mock ;
158
+ $ responses [] = new MockResponse ('' , ['error ' => 'Timeout ' ]);
173
159
break ;
174
160
175
161
case 'testAcceptHeader ' :
@@ -231,16 +217,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
231
217
break ;
232
218
233
219
case 'testMaxDuration ' :
234
- $ mock = $ this ->createMock (ResponseInterface::class);
235
- $ mock ->expects ($ this ->any ())
236
- ->method ('getContent ' )
237
- ->willReturnCallback (static function (): void {
238
- usleep (100000 );
239
-
240
- throw new TransportException ('Max duration was reached. ' );
241
- });
242
-
243
- $ responses [] = $ mock ;
220
+ $ responses [] = new MockResponse ('' , ['error ' => 'Max duration was reached. ' ]);
244
221
break ;
245
222
}
246
223
0 commit comments