Skip to content

Commit

Permalink
Add ability to test transfer time (#2362)
Browse files Browse the repository at this point in the history
* Add ability to test transfer time
  • Loading branch information
voprak authored and Nyholm committed Oct 18, 2019
1 parent 4013818 commit cbc63fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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);
$this->assertEquals(0.4, $stats->getTransferTime());
}
}

0 comments on commit cbc63fb

Please sign in to comment.