How to test TimeoutException for symfony/http-client #58392
-
Hello, I have a piece of code that reacts to a public function testTimeout(): void
{
$responses = [ /* A timeout response */];
$client = new MockHttpClient($responses);
$response = $client->request('GET', '/test');
$this->expectException(TimeoutException::class);
$this->assertEquals(200, $response->getStatusCode());
} My issue is that I cannot seem to find a way to produce a I tried with those responses: $responses = [new class extends MockResponse { public function getStatusCode(): int { throw new TimeoutException(); } }];
$responses = [new MockResponse((static fn () => yield new ErrorChunk(0, 'Timeout1'))())];
$responses = [new MockResponse([new ErrorChunk(0, 'Timeout')])]; They all seem to give an error in their Interestingly if I remove the last assert this test pass (but in my code I cannot remove this - $this->assertEquals(200, $response->getStatusCode());
+ $response->getStatusCode(); Does anyone have a suggestion? Am I misunderstanding this? Is there an issue in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
According to the docs:
|
Beta Was this translation helpful? Give feedback.
According to the docs: