ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP\ClientTest Class Reference
+ Inheritance diagram for Sabre\HTTP\ClientTest:
+ Collaboration diagram for Sabre\HTTP\ClientTest:

Public Member Functions

 testCreateCurlSettingsArrayGET ()
 
 testCreateCurlSettingsArrayHEAD ()
 
 testCreateCurlSettingsArrayGETAfterHEAD ()
 
 testCreateCurlSettingsArrayPUTStream ()
 
 testCreateCurlSettingsArrayPUTString ()
 
 testSend ()
 
 testSendClientError ()
 
 testSendHttpError ()
 
 testSendRetry ()
 
 testHttpErrorException ()
 
 testParseCurlResult ()
 
 testParseCurlError ()
 
 testDoRequest ()
 
 testDoRequestCurlError ()
 

Detailed Description

Definition at line 5 of file ClientTest.php.

Member Function Documentation

◆ testCreateCurlSettingsArrayGET()

Sabre\HTTP\ClientTest::testCreateCurlSettingsArrayGET ( )

Definition at line 7 of file ClientTest.php.

References $client, $request, and Sabre\HTTP\Version\VERSION.

7  {
8 
9  $client = new ClientMock();
10  $client->addCurlSetting(CURLOPT_POSTREDIR, 0);
11 
12  $request = new Request('GET', 'http://example.org/', ['X-Foo' => 'bar']);
13 
14  $settings = [
15  CURLOPT_RETURNTRANSFER => true,
16  CURLOPT_HEADER => true,
17  CURLOPT_POSTREDIR => 0,
18  CURLOPT_HTTPHEADER => ['X-Foo: bar'],
19  CURLOPT_NOBODY => false,
20  CURLOPT_URL => 'http://example.org/',
21  CURLOPT_CUSTOMREQUEST => 'GET',
22  CURLOPT_POSTFIELDS => '',
23  CURLOPT_PUT => false,
24  CURLOPT_USERAGENT => 'sabre-http/' . Version::VERSION . ' (http://sabre.io/)',
25  ];
26 
27  // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM
28  // at least if this unit test fails in the future we know it is :)
29  if (defined('HHVM_VERSION') === false) {
30  $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
31  $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
32  }
33 
34 
35  $this->assertEquals($settings, $client->createCurlSettingsArray($request));
36 
37  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
const VERSION
Full version number.
Definition: Version.php:17

◆ testCreateCurlSettingsArrayGETAfterHEAD()

Sabre\HTTP\ClientTest::testCreateCurlSettingsArrayGETAfterHEAD ( )

Definition at line 68 of file ClientTest.php.

References $client, $request, and Sabre\HTTP\Version\VERSION.

68  {
69 
70  $client = new ClientMock();
71  $request = new Request('HEAD', 'http://example.org/', ['X-Foo' => 'bar']);
72 
73  // Parsing the settings for this method, and discarding the result.
74  // This will cause the client to automatically persist previous
75  // settings and will help us detect problems.
76  $client->createCurlSettingsArray($request);
77 
78  // This is the real request.
79  $request = new Request('GET', 'http://example.org/', ['X-Foo' => 'bar']);
80 
81  $settings = [
82  CURLOPT_CUSTOMREQUEST => 'GET',
83  CURLOPT_RETURNTRANSFER => true,
84  CURLOPT_HEADER => true,
85  CURLOPT_HTTPHEADER => ['X-Foo: bar'],
86  CURLOPT_NOBODY => false,
87  CURLOPT_URL => 'http://example.org/',
88  CURLOPT_POSTFIELDS => '',
89  CURLOPT_PUT => false,
90  CURLOPT_USERAGENT => 'sabre-http/' . Version::VERSION . ' (http://sabre.io/)',
91  ];
92 
93  // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM
94  // at least if this unit test fails in the future we know it is :)
95  if (defined('HHVM_VERSION') === false) {
96  $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
97  $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
98  }
99 
100  $this->assertEquals($settings, $client->createCurlSettingsArray($request));
101 
102  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
const VERSION
Full version number.
Definition: Version.php:17

◆ testCreateCurlSettingsArrayHEAD()

Sabre\HTTP\ClientTest::testCreateCurlSettingsArrayHEAD ( )

Definition at line 39 of file ClientTest.php.

References $client, $request, and Sabre\HTTP\Version\VERSION.

39  {
40 
41  $client = new ClientMock();
42  $request = new Request('HEAD', 'http://example.org/', ['X-Foo' => 'bar']);
43 
44 
45  $settings = [
46  CURLOPT_RETURNTRANSFER => true,
47  CURLOPT_HEADER => true,
48  CURLOPT_NOBODY => true,
49  CURLOPT_CUSTOMREQUEST => 'HEAD',
50  CURLOPT_HTTPHEADER => ['X-Foo: bar'],
51  CURLOPT_URL => 'http://example.org/',
52  CURLOPT_POSTFIELDS => '',
53  CURLOPT_PUT => false,
54  CURLOPT_USERAGENT => 'sabre-http/' . Version::VERSION . ' (http://sabre.io/)',
55  ];
56 
57  // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM
58  // at least if this unit test fails in the future we know it is :)
59  if (defined('HHVM_VERSION') === false) {
60  $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
61  $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
62  }
63 
64  $this->assertEquals($settings, $client->createCurlSettingsArray($request));
65 
66  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
const VERSION
Full version number.
Definition: Version.php:17

◆ testCreateCurlSettingsArrayPUTStream()

Sabre\HTTP\ClientTest::testCreateCurlSettingsArrayPUTStream ( )

Definition at line 104 of file ClientTest.php.

References $client, $h, $request, and Sabre\HTTP\Version\VERSION.

104  {
105 
106  $client = new ClientMock();
107 
108  $h = fopen('php://memory', 'r+');
109  fwrite($h, 'booh');
110  $request = new Request('PUT', 'http://example.org/', ['X-Foo' => 'bar'], $h);
111 
112  $settings = [
113  CURLOPT_RETURNTRANSFER => true,
114  CURLOPT_HEADER => true,
115  CURLOPT_PUT => true,
116  CURLOPT_INFILE => $h,
117  CURLOPT_NOBODY => false,
118  CURLOPT_CUSTOMREQUEST => 'PUT',
119  CURLOPT_HTTPHEADER => ['X-Foo: bar'],
120  CURLOPT_URL => 'http://example.org/',
121  CURLOPT_USERAGENT => 'sabre-http/' . Version::VERSION . ' (http://sabre.io/)',
122  ];
123 
124  // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM
125  // at least if this unit test fails in the future we know it is :)
126  if (defined('HHVM_VERSION') === false) {
127  $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
128  $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
129  }
130 
131  $this->assertEquals($settings, $client->createCurlSettingsArray($request));
132 
133  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
$h
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
const VERSION
Full version number.
Definition: Version.php:17

◆ testCreateCurlSettingsArrayPUTString()

Sabre\HTTP\ClientTest::testCreateCurlSettingsArrayPUTString ( )

Definition at line 135 of file ClientTest.php.

References $client, $request, and Sabre\HTTP\Version\VERSION.

135  {
136 
137  $client = new ClientMock();
138  $request = new Request('PUT', 'http://example.org/', ['X-Foo' => 'bar'], 'boo');
139 
140  $settings = [
141  CURLOPT_RETURNTRANSFER => true,
142  CURLOPT_HEADER => true,
143  CURLOPT_NOBODY => false,
144  CURLOPT_POSTFIELDS => 'boo',
145  CURLOPT_CUSTOMREQUEST => 'PUT',
146  CURLOPT_HTTPHEADER => ['X-Foo: bar'],
147  CURLOPT_URL => 'http://example.org/',
148  CURLOPT_USERAGENT => 'sabre-http/' . Version::VERSION . ' (http://sabre.io/)',
149  ];
150 
151  // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM
152  // at least if this unit test fails in the future we know it is :)
153  if (defined('HHVM_VERSION') === false) {
154  $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
155  $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
156  }
157 
158  $this->assertEquals($settings, $client->createCurlSettingsArray($request));
159 
160  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
const VERSION
Full version number.
Definition: Version.php:17

◆ testDoRequest()

Sabre\HTTP\ClientTest::testDoRequest ( )

Definition at line 320 of file ClientTest.php.

References $client, $request, and $response.

320  {
321 
322  $client = new ClientMock();
323  $request = new Request('GET', 'http://example.org/');
324  $client->on('curlExec', function(&$return) {
325 
326  $return = "HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
327 
328  });
329  $client->on('curlStuff', function(&$return) {
330 
331  $return = [
332  [
333  'header_size' => 33,
334  'http_code' => 200,
335  ],
336  0,
337  '',
338  ];
339 
340  });
341  $response = $client->doRequest($request);
342  $this->assertEquals(200, $response->getStatus());
343  $this->assertEquals(['Header1' => ['Val1']], $response->getHeaders());
344  $this->assertEquals('Foo', $response->getBodyAsString());
345 
346  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response

◆ testDoRequestCurlError()

Sabre\HTTP\ClientTest::testDoRequestCurlError ( )

Definition at line 348 of file ClientTest.php.

References $client, $request, and $response.

348  {
349 
350  $client = new ClientMock();
351  $request = new Request('GET', 'http://example.org/');
352  $client->on('curlExec', function(&$return) {
353 
354  $return = "";
355 
356  });
357  $client->on('curlStuff', function(&$return) {
358 
359  $return = [
360  [],
361  1,
362  'Curl error',
363  ];
364 
365  });
366 
367  try {
368  $response = $client->doRequest($request);
369  $this->fail('This should have thrown an exception');
370  } catch (ClientException $e) {
371  $this->assertEquals(1, $e->getCode());
372  $this->assertEquals('Curl error', $e->getMessage());
373  }
374 
375  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response

◆ testHttpErrorException()

Sabre\HTTP\ClientTest::testHttpErrorException ( )

Definition at line 251 of file ClientTest.php.

References $client, $request, $response, Sabre\HTTP\ClientHttpException\getHttpStatus(), and Sabre\HTTP\ClientHttpException\getResponse().

251  {
252 
253  $client = new ClientMock();
254  $client->setThrowExceptions(true);
255  $request = new Request('GET', 'http://example.org/');
256 
257  $client->on('doRequest', function($request, &$response) {
258  $response = new Response(404);
259  });
260 
261  try {
262  $client->send($request);
263  $this->fail('An exception should have been thrown');
264  } catch (ClientHttpException $e) {
265  $this->assertEquals(404, $e->getHttpStatus());
266  $this->assertInstanceOf('Sabre\HTTP\Response', $e->getResponse());
267  }
268 
269  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response
+ Here is the call graph for this function:

◆ testParseCurlError()

Sabre\HTTP\ClientTest::testParseCurlError ( )

Definition at line 298 of file ClientTest.php.

References $client, $result, and Sabre\HTTP\Client\STATUS_CURLERROR.

298  {
299 
300  $client = new ClientMock();
301  $client->on('curlStuff', function(&$return) {
302 
303  $return = [
304  [],
305  1,
306  'Curl error',
307  ];
308 
309  });
310 
311  $body = "HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
312  $result = $client->parseCurlResult($body, 'foobar');
313 
314  $this->assertEquals(Client::STATUS_CURLERROR, $result['status']);
315  $this->assertEquals(1, $result['curl_errno']);
316  $this->assertEquals('Curl error', $result['curl_errmsg']);
317 
318  }
$result
const STATUS_CURLERROR
Definition: Client.php:456
if($_SERVER['argc']< 4) $client
Definition: cron.php:12

◆ testParseCurlResult()

Sabre\HTTP\ClientTest::testParseCurlResult ( )

Definition at line 271 of file ClientTest.php.

References $client, $result, Sabre\HTTP\getBodyAsString(), Sabre\HTTP\getHeaders(), and Sabre\HTTP\Client\STATUS_SUCCESS.

271  {
272 
273  $client = new ClientMock();
274  $client->on('curlStuff', function(&$return) {
275 
276  $return = [
277  [
278  'header_size' => 33,
279  'http_code' => 200,
280  ],
281  0,
282  '',
283  ];
284 
285  });
286 
287  $body = "HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
288  $result = $client->parseCurlResult($body, 'foobar');
289 
290  $this->assertEquals(Client::STATUS_SUCCESS, $result['status']);
291  $this->assertEquals(200, $result['http_code']);
292  $this->assertEquals(200, $result['response']->getStatus());
293  $this->assertEquals(['Header1' => ['Val1']], $result['response']->getHeaders());
294  $this->assertEquals('Foo', $result['response']->getBodyAsString());
295 
296  }
const STATUS_SUCCESS
Definition: Client.php:455
$result
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
getHeaders()
Returns all the HTTP headers as an array.
getBodyAsString()
Returns the body as a string.
+ Here is the call graph for this function:

◆ testSend()

Sabre\HTTP\ClientTest::testSend ( )

Definition at line 162 of file ClientTest.php.

References $client, $request, and $response.

162  {
163 
164  $client = new ClientMock();
165  $request = new Request('GET', 'http://example.org/');
166 
167  $client->on('doRequest', function($request, &$response) {
168  $response = new Response(200);
169  });
170 
171  $response = $client->send($request);
172 
173  $this->assertEquals(200, $response->getStatus());
174 
175  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response

◆ testSendClientError()

Sabre\HTTP\ClientTest::testSendClientError ( )

Definition at line 177 of file ClientTest.php.

References $client, $request, and $response.

177  {
178 
179  $client = new ClientMock();
180  $request = new Request('GET', 'http://example.org/');
181 
182  $client->on('doRequest', function($request, &$response) {
183  throw new ClientException('aaah', 1);
184  });
185  $called = false;
186  $client->on('exception', function() use (&$called) {
187  $called = true;
188  });
189 
190  try {
191  $client->send($request);
192  $this->fail('send() should have thrown an exception');
193  } catch (ClientException $e) {
194 
195  }
196  $this->assertTrue($called);
197 
198  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response

◆ testSendHttpError()

Sabre\HTTP\ClientTest::testSendHttpError ( )

Definition at line 200 of file ClientTest.php.

References $client, $request, and $response.

200  {
201 
202  $client = new ClientMock();
203  $request = new Request('GET', 'http://example.org/');
204 
205  $client->on('doRequest', function($request, &$response) {
206  $response = new Response(404);
207  });
208  $called = 0;
209  $client->on('error', function() use (&$called) {
210  $called++;
211  });
212  $client->on('error:404', function() use (&$called) {
213  $called++;
214  });
215 
216  $client->send($request);
217  $this->assertEquals(2, $called);
218 
219  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response

◆ testSendRetry()

Sabre\HTTP\ClientTest::testSendRetry ( )

Definition at line 221 of file ClientTest.php.

References $client, $request, $response, and $retry.

221  {
222 
223  $client = new ClientMock();
224  $request = new Request('GET', 'http://example.org/');
225 
226  $called = 0;
227  $client->on('doRequest', function($request, &$response) use (&$called) {
228  $called++;
229  if ($called < 3) {
230  $response = new Response(404);
231  } else {
232  $response = new Response(200);
233  }
234  });
235 
236  $errorCalled = 0;
237  $client->on('error', function($request, $response, &$retry, $retryCount) use (&$errorCalled) {
238 
239  $errorCalled++;
240  $retry = true;
241 
242  });
243 
244  $response = $client->send($request);
245  $this->assertEquals(3, $called);
246  $this->assertEquals(2, $errorCalled);
247  $this->assertEquals(200, $response->getStatus());
248 
249  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response

The documentation for this class was generated from the following file: