Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to test transfer time #2362

Merged
merged 2 commits into from Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Handler/MockHandler.php
Expand Up @@ -182,7 +182,8 @@ private function invokeStats(
$reason = null
) {
if (isset($options['on_stats'])) {
$stats = new TransferStats($request, $response, 0, $reason);
$transferTime = isset($options['transfer_time']) ? $options['transfer_time'] : 0;
$stats = new TransferStats($request, $response, $transferTime, $reason);
call_user_func($options['on_stats'], $stats);
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Handler/MockHandlerTest.php
Expand Up @@ -221,4 +221,18 @@ public function testInvokesOnStatsFunctionForError()
$this->assertNull($stats->getResponse());
$this->assertSame($request, $stats->getRequest());
}

public function testTransferTime()
{
$e = new \Exception('a');
$c = null;
$mock = new MockHandler([$e], null, function ($v) use (&$c) { $c = $v; });
$request = new Request('GET', 'http://example.com');
$stats = null;
$onStats = function (TransferStats $s) use (&$stats) {
$stats = $s;
};
$mock($request, ['on_stats' => $onStats, 'transfer_time' => 0.4])->wait(false);
Nyholm marked this conversation as resolved.
Show resolved Hide resolved
$this->assertEquals(0.4,$stats->getTransferTime());
Nyholm marked this conversation as resolved.
Show resolved Hide resolved
}
}