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
{
@@ -272,16 +271,8 @@ protected function getHttpClient(string $testCase): HttpClientInterface
272
271
break ;
273
272
274
273
case 'testDnsError ' :
275
- $ mock = $ this ->createMock (ResponseInterface::class);
276
- $ mock ->expects ($ this ->any ())
277
- ->method ('getStatusCode ' )
278
- ->willThrowException (new TransportException ('DSN error ' ));
279
- $ mock ->expects ($ this ->any ())
280
- ->method ('getInfo ' )
281
- ->willReturn ([]);
282
-
283
- $ responses [] = $ mock ;
284
- $ responses [] = $ mock ;
274
+ $ responses [] = $ mockResponse = new MockResponse ('' , ['error ' => 'DNS error ' ]);
275
+ $ responses [] = $ mockResponse ;
285
276
break ;
286
277
287
278
case 'testToStream ' :
@@ -295,12 +286,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
295
286
break ;
296
287
297
288
case 'testTimeoutOnAccess ' :
298
- $ mock = $ this ->createMock (ResponseInterface::class);
299
- $ mock ->expects ($ this ->any ())
300
- ->method ('getHeaders ' )
301
- ->willThrowException (new TransportException ('Timeout ' ));
302
-
303
- $ responses [] = $ mock ;
289
+ $ responses [] = new MockResponse ('' , ['error ' => 'Timeout ' ]);
304
290
break ;
305
291
306
292
case 'testAcceptHeader ' :
@@ -362,16 +348,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
362
348
break ;
363
349
364
350
case 'testMaxDuration ' :
365
- $ mock = $ this ->createMock (ResponseInterface::class);
366
- $ mock ->expects ($ this ->any ())
367
- ->method ('getContent ' )
368
- ->willReturnCallback (static function (): void {
369
- usleep (100000 );
370
-
371
- throw new TransportException ('Max duration was reached. ' );
372
- });
373
-
374
- $ responses [] = $ mock ;
351
+ $ responses [] = new MockResponse ('' , ['error ' => 'Max duration was reached. ' ]);
375
352
break ;
376
353
}
377
354
0 commit comments