public function testInvokesOnStatsOnError()
{
$req = new Psr7\Request('GET', 'http://127.0.0.1:123');
$gotStats = null;
$handler = new StreamHandler();
$promise = $handler($req, ['connect_timeout' => 0.001, 'timeout' => 0.001, 'on_stats' => function (TransferStats $stats) use(&$gotStats) {
$gotStats = $stats;
}]);
$promise->wait(false);
$this->assertFalse($gotStats->hasResponse());
$this->assertEquals('http://127.0.0.1:123', (string) $gotStats->getEffectiveUri());
$this->assertEquals('http://127.0.0.1:123', (string) $gotStats->getRequest()->getUri());
$this->assertInternalType('float', $gotStats->getTransferTime());
$this->assertInstanceOf(ConnectException::class, $gotStats->getHandlerErrorData());
}