public function testCreatesCurlHandle()
{
Server::flush();
Server::enqueue([new Psr7\Response(200, ['Foo' => 'Bar', 'Baz' => 'bam', 'Content-Length' => 2], 'hi')]);
$stream = Psr7\stream_for();
$request = new Psr7\Request('PUT', Server::$url, ['Hi' => ' 123', 'Content-Length' => '7'], 'testing');
$f = new Handler\CurlFactory(3);
$result = $f->create($request, ['sink' => $stream]);
$this->assertInstanceOf(EasyHandle::class, $result);
$this->assertInternalType('resource', $result->handle);
$this->assertInternalType('array', $result->headers);
$this->assertSame($stream, $result->sink);
curl_close($result->handle);
$this->assertEquals('PUT', $_SERVER['_curl'][CURLOPT_CUSTOMREQUEST]);
$this->assertEquals('http://127.0.0.1:8126/', $_SERVER['_curl'][CURLOPT_URL]);
// Sends via post fields when the request is small enough
$this->assertEquals('testing', $_SERVER['_curl'][CURLOPT_POSTFIELDS]);
$this->assertEquals(0, $_SERVER['_curl'][CURLOPT_RETURNTRANSFER]);
$this->assertEquals(0, $_SERVER['_curl'][CURLOPT_HEADER]);
$this->assertEquals(150, $_SERVER['_curl'][CURLOPT_CONNECTTIMEOUT]);
$this->assertInstanceOf('Closure', $_SERVER['_curl'][CURLOPT_HEADERFUNCTION]);
if (defined('CURLOPT_PROTOCOLS')) {
$this->assertEquals(CURLPROTO_HTTP | CURLPROTO_HTTPS, $_SERVER['_curl'][CURLOPT_PROTOCOLS]);
}
$this->assertContains('Expect:', $_SERVER['_curl'][CURLOPT_HTTPHEADER]);
$this->assertContains('Accept:', $_SERVER['_curl'][CURLOPT_HTTPHEADER]);
$this->assertContains('Content-Type:', $_SERVER['_curl'][CURLOPT_HTTPHEADER]);
$this->assertContains('Hi: 123', $_SERVER['_curl'][CURLOPT_HTTPHEADER]);
$this->assertContains('Host: 127.0.0.1:8126', $_SERVER['_curl'][CURLOPT_HTTPHEADER]);
}