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 a5683c5

Browse filesBrowse files
bug #40239 MockResponse total_time should not be simulated when provided (Pierrick VIGNAND)
This PR was merged into the 4.4 branch. Discussion ---------- MockResponse total_time should not be simulated when provided | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | When you provide a `total_time` to a MockResponse, it is overriden. It should be simulated only when it is not provided I guess. Ex: `new MockResponse('{"foo":"bar"}', ['total_time' => 0.4])` Commits ------- 8dada95 fix: MockResponse total_time should not be simulated when provided
2 parents 3fe1564 + 8dada95 commit a5683c5
Copy full SHA for a5683c5

File tree

2 files changed

+22
-4
lines changed
Filter options

2 files changed

+22
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/MockResponse.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ private static function writeRequest(self $response, array $options, ResponseInt
211211
$response->info['size_upload'] = 0.0;
212212
}
213213

214-
// simulate "total_time" if it is set
215-
if (isset($response->info['total_time'])) {
214+
// simulate "total_time" if it is not set
215+
if (!isset($response->info['total_time'])) {
216216
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
217217
}
218218

@@ -260,7 +260,7 @@ private static function readResponse(self $response, array $options, ResponseInt
260260
'http_code' => $response->info['http_code'],
261261
] + $info + $response->info;
262262

263-
if (isset($response->info['total_time'])) {
263+
if (!isset($response->info['total_time'])) {
264264
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
265265
}
266266

@@ -287,7 +287,7 @@ private static function readResponse(self $response, array $options, ResponseInt
287287
$offset = \strlen($body);
288288
}
289289

290-
if (isset($response->info['total_time'])) {
290+
if (!isset($response->info['total_time'])) {
291291
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
292292
}
293293

‎src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
*/
1212
class MockResponseTest extends TestCase
1313
{
14+
public function testTotalTimeShouldBeSimulatedWhenNotProvided()
15+
{
16+
$response = new MockResponse('body');
17+
$response = MockResponse::fromRequest('GET', 'https://example.com/file.txt', [], $response);
18+
19+
$this->assertNotNull($response->getInfo('total_time'));
20+
$this->assertGreaterThan(0.0, $response->getInfo('total_time'));
21+
}
22+
23+
public function testTotalTimeShouldNotBeSimulatedWhenProvided()
24+
{
25+
$totalTime = 4.2;
26+
$response = new MockResponse('body', ['total_time' => $totalTime]);
27+
$response = MockResponse::fromRequest('GET', 'https://example.com/file.txt', [], $response);
28+
29+
$this->assertEquals($totalTime, $response->getInfo('total_time'));
30+
}
31+
1432
public function testToArray()
1533
{
1634
$data = ['color' => 'orange', 'size' => 42];

0 commit comments

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