Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd5a4ca

Browse filesBrowse files
committed
[HttpClient] Improve MockHttpClient exception message
1 parent 2a2fc8a commit bd5a4ca
Copy full SHA for bd5a4ca

File tree

Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed

‎src/Symfony/Component/HttpClient/MockHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/MockHttpClient.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function request(string $method, string $url, array $options = []): Respo
7272
} elseif (\is_callable($this->responseFactory)) {
7373
$response = ($this->responseFactory)($method, $url, $options);
7474
} elseif (!$this->responseFactory->valid()) {
75-
throw new TransportException('The response factory iterator passed to MockHttpClient is empty.');
75+
throw new TransportException($this->requestsCount ? 'No more response left in the response factory iterator passed to MockHttpClient: the number of requests exceeds the number of responses.' : 'The response factory iterator passed to MockHttpClient is empty.');
7676
} else {
7777
$responseFactory = $this->responseFactory->current();
7878
$response = \is_callable($responseFactory) ? $responseFactory($method, $url, $options) : $responseFactory;

‎src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,23 @@ public function testCancelingMockResponseExecutesOnProgressWithUpdatedInfo()
527527

528528
$this->assertTrue($canceled);
529529
}
530+
531+
public function testEmptyResponseFactory()
532+
{
533+
$this->expectException(TransportException::class);
534+
$this->expectExceptionMessage('The response factory iterator passed to MockHttpClient is empty.');
535+
536+
$client = new MockHttpClient([]);
537+
$client->request('GET', 'https://example.com');
538+
}
539+
540+
public function testMoreRequestsThanResponseFactoryResponses()
541+
{
542+
$this->expectException(TransportException::class);
543+
$this->expectExceptionMessage('No more response left in the response factory iterator passed to MockHttpClient: the number of requests exceeds the number of responses.');
544+
545+
$client = new MockHttpClient([new MockResponse()]);
546+
$client->request('GET', 'https://example.com');
547+
$client->request('GET', 'https://example.com');
548+
}
530549
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.