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 d5423db

Browse filesBrowse files
minor #50062 [HttpClient] Improve MockHttpClient exception message (fancyweb)
This PR was merged into the 6.3 branch. Discussion ---------- [HttpClient] Improve MockHttpClient exception message | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #49874 (comment) | License | MIT | Doc PR | - When using `MockHttpClient`, if there are more requests done on the client than the passed available responses, the exception message is misleading. ~Targeting 5.4 since it only changes the exception message 😅~ Commits ------- bd5a4ca [HttpClient] Improve MockHttpClient exception message
2 parents 33da4c8 + bd5a4ca commit d5423db
Copy full SHA for d5423db

File tree

2 files changed

+20
-1
lines changed
Filter options

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
@@ -69,7 +69,7 @@ public function request(string $method, string $url, array $options = []): Respo
6969
} elseif (\is_callable($this->responseFactory)) {
7070
$response = ($this->responseFactory)($method, $url, $options);
7171
} elseif (!$this->responseFactory->valid()) {
72-
throw new TransportException('The response factory iterator passed to MockHttpClient is empty.');
72+
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.');
7373
} else {
7474
$responseFactory = $this->responseFactory->current();
7575
$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
@@ -554,4 +554,23 @@ public function testCancelingMockResponseExecutesOnProgressWithUpdatedInfo()
554554

555555
$this->assertTrue($canceled);
556556
}
557+
558+
public function testEmptyResponseFactory()
559+
{
560+
$this->expectException(TransportException::class);
561+
$this->expectExceptionMessage('The response factory iterator passed to MockHttpClient is empty.');
562+
563+
$client = new MockHttpClient([]);
564+
$client->request('GET', 'https://example.com');
565+
}
566+
567+
public function testMoreRequestsThanResponseFactoryResponses()
568+
{
569+
$this->expectException(TransportException::class);
570+
$this->expectExceptionMessage('No more response left in the response factory iterator passed to MockHttpClient: the number of requests exceeds the number of responses.');
571+
572+
$client = new MockHttpClient([new MockResponse()]);
573+
$client->request('GET', 'https://example.com');
574+
$client->request('GET', 'https://example.com');
575+
}
557576
}

0 commit comments

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