8000 feature #52775 [HttpClient] Allow mocking `start_time` info in `MockR… · symfony/symfony@0d9562f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d9562f

Browse files
committed
feature #52775 [HttpClient] Allow mocking start_time info in MockResponse (fancyweb)
This PR was merged into the 7.1 branch. Discussion ---------- [HttpClient] Allow mocking `start_time` info in `MockResponse` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Let's honor the custom `start_time` passed to `MockResponse`. My use case is that the current behavior prevents me from easily testing code using this info. Commits ------- 7ace621 [HttpClient] Allow mocking start_time info in MockResponse
2 parents 454d16b + 7ace621 commit 0d9562f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/Symfony/Component/HttpClient/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Allow mocking `start_time` info in `MockResponse`
8+
49
7.0
510
---
611

src/Symfony/Component/HttpClient/Response/MockResponse.php

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ private static function writeRequest(self $response, array $options, ResponseInt
217217
{
218218
$onProgress = $options['on_progress'] ?? static function () {};
219219
$response->info += $mock->getInfo() ?: [];
220+
if (null !== $mock->getInfo('start_time')) {
221+
$response->info['start_time'] = $mock->getInfo('start_time');
222+
}
220223

221224
// simulate "size_upload" if it is set
222225
if (isset($response->info['size_upload'])) {

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

+10
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,14 @@ public function testMoreRequestsThanResponseFactoryResponses()
573573
$client->request('GET', 'https://example.com');
574574
$client->request('GET', 'https://example.com');
575575
}
576+
577+
public function testMockStartTimeInfo()
578+
{
579+
$client = new MockHttpClient(new MockResponse('foobarccc', [
580+
'start_time' => 1701187598.313123,
581+
]));
582+
583+
$response = $client->request('GET', 'https://example.com');
584+
$this->assertSame(1701187598.313123, $response->getInfo('start_time'));
585+
}
576586
}

0 commit comments

Comments
 (0)
0