Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Symfony/Component/HttpClient/Response/MockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ private static function writeRequest(self $response, array $options, ResponseInt
$response->info['size_upload'] = 0.0;
}

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

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

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

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

if (isset($response->info['total_time'])) {
if (!isset($response->info['total_time'])) {
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
}
Comment on lines -290 to 292
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To measure the time that passes between the two calls.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
*/
class MockResponseTest extends TestCase
{
public function testTotalTimeShouldBeSimulatedWhenNotProvided()
{
$response = new MockResponse('body');
$response = MockResponse::fromRequest('GET', 'https://example.com/file.txt', [], $response);

$this->assertNotNull($response->getInfo('total_time'));
$this->assertGreaterThan(0.0, $response->getInfo('total_time'));
}

public function testTotalTimeShouldNotBeSimulatedWhenProvided()
{
$totalTime = 4.2;
$response = new MockResponse('body', ['total_time' => $totalTime]);
$response = MockResponse::fromRequest('GET', 'https://example.com/file.txt', [], $response);

$this->assertEquals($totalTime, $response->getInfo('total_time'));
}

public function testToArray()
{
$data = ['color' => 'orange', 'size' => 42];
Expand Down