|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\HttpClient\Exception\JsonException;
|
| 16 | +use Symfony\Component\HttpClient\Exception\TimeoutException; |
16 | 17 | use Symfony\Component\HttpClient\Exception\TransportException;
|
17 | 18 | use Symfony\Component\HttpClient\Response\MockResponse;
|
18 | 19 |
|
@@ -124,4 +125,34 @@ public function testCancelingAMockResponseNotIssuedByMockHttpClient()
|
124 | 125 |
|
125 | 126 | $this->assertTrue($mockResponse->getInfo('canceled'));
|
126 | 127 | }
|
| 128 | + |
| 129 | + public function testTimeoutHeader() |
| 130 | + { |
| 131 | + $response = MockResponse::fromRequest('GET', 'http://symfony.com', [], new MockResponse([''])); |
| 132 | + |
| 133 | + try { |
| 134 | + $response->getStatusCode(); |
| 135 | + $this->fail(TimeoutException::class.' expected'); |
| 136 | + } catch (TimeoutException $e) { |
| 137 | + } |
| 138 | + |
| 139 | + $this->assertSame('Idle timeout reached for "http://symfony.com".', $response->getInfo('error')); |
| 140 | + } |
| 141 | + |
| 142 | + public function testTimeoutBody() |
| 143 | + { |
| 144 | + $response = MockResponse::fromRequest('GET', 'http://symfony.com', [], new MockResponse(['content', ''])); |
| 145 | + |
| 146 | + try { |
| 147 | + $this->assertSame(200, $response->getStatusCode()); |
| 148 | + } catch (TimeoutException $e) { |
| 149 | + $this->fail(TimeoutException::class.' was not expected'); |
| 150 | + } |
| 151 | + |
| 152 | + try { |
| 153 | + $response->getContent(); |
| 154 | + $this->fail(TimeoutException::class.' expected'); |
| 155 | + } catch (TimeoutException $e) { |
| 156 | + } |
| 157 | + } |
127 | 158 | }
|
0 commit comments