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 ' :
@@ -296,12 +287,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
296
287
break ;
297
288
298
289
case 'testTimeoutOnAccess ' :
299
- $ mock = $ this ->createMock (ResponseInterface::class);
300
- $ mock ->expects ($ this ->any ())
301
- ->method ('getHeaders ' )
302
- ->willThrowException (new TransportException ('Timeout ' ));
303
-
304
- $ responses [] = $ mock ;
290
+ $ responses [] = new MockResponse ('' , ['error ' => 'Timeout ' ]);
305
291
break ;
306
292
307
293
case 'testAcceptHeader ' :
@@ -363,16 +349,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
363
349
break ;
364
350
365
351
case 'testMaxDuration ' :
366
- $ mock = $ this ->createMock (ResponseInterface::class);
367
- $ mock ->expects ($ this ->any ())
368
- ->method ('getContent ' )
369
- ->willReturnCallback (static function (): void {
370
- usleep (100000 );
371
-
372
- throw new TransportException ('Max duration was reached. ' );
373
- });
374
-
375
- $ responses [] = $ mock ;
352
+ $ responses [] = new MockResponse ('' , ['error ' => 'Max duration was reached. ' ]);
376
353
break ;
377
354
}
378
355
0 commit comments