1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace GuzzleHttp\Tests\Ring\Client;
use GuzzleHttp\Ring\Client\CurlHandler;
class CurlHandlerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!function_exists('curl_reset')) {
$this->markTestSkipped('curl_reset() is not available');
}
}
protected function getHandler($factory = null, $options = [])
{
return new CurlHandler($options);
}
public function testCanSetMaxHandles()
{
$a = new CurlHandler(['max_handles' => 10]);
$this->assertEquals(10, $this->readAttribute($a, 'maxHandles'));
}
public function testCreatesCurlErrors()
{
$handler = new CurlHandler();
$response = $handler([
'http_method' => 'GET',
'uri' => '/',
'headers' => ['host' => ['localhost:123']],
'client' => ['timeout' => 0.001, 'connect_timeout' => 0.001],
]);
$this->assertNull($response['status']);
$this->assertNull($response['reason']);
$this->assertEquals([], $response['headers']);
$this->assertInstanceOf(
'GuzzleHttp\Ring\Exception\RingException',
$response['error']
);
$this->assertEquals(
1,
preg_match('/^cURL error \d+: .*$/', $response['error']->getMessage())
);
}
public function testReleasesAdditionalEasyHandles()
{
Server::flush();
$response = [
'status' => 200,
'headers' => ['Content-Length' => [4]],
'body' => 'test',
];
Server::enqueue([$response, $response, $response, $response]);
$a = new CurlHandler(['max_handles' => 2]);
$fn = function () use (&$calls, $a, &$fn) {
if (++$calls < 4) {
$a([
'http_method' => 'GET',
'headers' => ['host' => [Server::$host]],
'client' => ['progress' => $fn],
]);
}
};
$request = [
'http_method' => 'GET',
'headers' => ['host' => [Server::$host]],
'client' => [
'progress' => $fn,
],
];
$a($request);
$this->assertCount(2, $this->readAttribute($a, 'handles'));
}
public function testReusesHandles()
{
Server::flush();
$response = ['status' => 200];
Server::enqueue([$response, $response]);
$a = new CurlHandler();
$request = [
'http_method' => 'GET',
'headers' => ['host' => [Server::$host]],
];
$a($request);
$a($request);
}
}