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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy