diff --git a/src/Handler/MockHandler.php b/src/Handler/MockHandler.php index d892061c7..d5c449c1d 100644 --- a/src/Handler/MockHandler.php +++ b/src/Handler/MockHandler.php @@ -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); } } diff --git a/tests/Handler/MockHandlerTest.php b/tests/Handler/MockHandlerTest.php index e067a8b48..f050ef299 100644 --- a/tests/Handler/MockHandlerTest.php +++ b/tests/Handler/MockHandlerTest.php @@ -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()); + } }