26 $that->requestHandle = $e[
'handle'];
34 $this->requestHandle =
null;
47 $h = curl_init($this->
getServer()->getUrl());
50 $this->fail(
'Expected InvalidArgumentException');
51 }
catch (\InvalidArgumentException $e) {
55 CURLOPT_URL => $this->
getServer()->getUrl()
57 $this->assertEquals($this->
getServer()->getUrl(), $ha->getOptions()->get(CURLOPT_URL));
60 CURLOPT_URL => $this->
getServer()->getUrl()
62 $this->assertEquals($this->
getServer()->getUrl(), $ha->getOptions()->get(CURLOPT_URL));
67 $handle = curl_init($this->
getServer()->getUrl());
69 CURLOPT_URL => $this->
getServer()->getUrl()
71 $this->assertSame($handle, $h->getHandle());
72 $this->assertInstanceOf(
'Guzzle\\Http\\Url', $h->getUrl());
73 $this->assertEquals($this->
getServer()->getUrl(), (
string) $h->getUrl());
74 $this->assertEquals($this->
getServer()->getUrl(), $h->getOptions()->get(CURLOPT_URL));
80 $request->getCurlOptions()->set(
'debug',
true);
82 $this->assertEquals($h->getStderr(
true), $h->getOptions()->get(CURLOPT_STDERR));
83 $this->assertInternalType(
'resource', $h->getStderr(
true));
84 $this->assertInternalType(
'string', $h->getStderr(
false));
85 $r = $h->getStderr(
true);
87 $this->assertEquals(
'test', $h->getStderr(
false));
92 $h =
new CurlHandle(curl_init(
'http://test.com'), array(CURLOPT_URL =>
'http://test.com'));
93 $this->assertEquals(CURLE_OK, $h->getErrorNo());
94 $h->setErrorNo(CURLE_OPERATION_TIMEOUTED);
95 $this->assertEquals(CURLE_OPERATION_TIMEOUTED, $h->getErrorNo());
100 $handle = curl_init(
'http://www.test.com/');
102 CURLOPT_URL =>
'http://www.test.com/'
104 $this->assertNull($h->getStderr(
false));
109 $handle = curl_init($this->
getServer()->getUrl());
111 $this->assertTrue($h->isAvailable());
115 $this->assertFalse($h->isAvailable());
119 $this->assertFalse($h->isAvailable());
124 if (!defined(
'CURLOPT_TIMEOUT_MS')) {
125 $this->markTestSkipped(
'Update curl');
130 CURLOPT_CONNECTTIMEOUT_MS => 1,
131 CURLOPT_TIMEOUT_MS => 1
134 $handle = curl_init($this->
getServer()->getUrl());
135 curl_setopt_array($handle, $settings);
140 "couldn't connect to host",
141 'timeout was reached',
142 'connection time-out',
143 'connect() timed out!',
144 'failed connect to 127.0.0.1:123; connection refused',
145 'failed to connect to 127.0.0.1 port 123: connection refused'
147 $this->assertTrue(in_array(strtolower($h->getError()), $errors), $h->getError() .
' was not the error');
149 $this->assertTrue($h->getErrorNo() > 0);
151 $this->assertEquals($this->
getServer()->getUrl(), $h->getInfo(CURLINFO_EFFECTIVE_URL));
152 $this->assertInternalType(
'array', $h->getInfo());
155 $this->assertEquals(
null, $h->getInfo(
'url'));
160 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
162 $request = $client->get($this->
getServer()->getUrl());
163 $response = $request->send();
165 $info = $response->getInfo();
166 $this->assertFalse(empty($info));
167 $this->assertEquals($this->
getServer()->getUrl(), $info[
'url']);
172 $handle = curl_init($this->
getServer()->getUrl());
174 CURLOPT_AUTOREFERER =>
true,
175 CURLOPT_BUFFERSIZE => 1024
178 $this->assertEquals(
true, $h->getOptions()->get(CURLOPT_AUTOREFERER));
179 $this->assertEquals(1024, $h->getOptions()->get(CURLOPT_BUFFERSIZE));
189 $testFile = __DIR__ .
'/../../../../../phpunit.xml.dist';
191 $postBody =
new QueryString(array(
'file' =>
'@' . $testFile));
198 $userAgent = $client->getDefaultUserAgent();
199 $auth = base64_encode(
'michael:123');
200 $testFileSize = filesize($testFile);
204 array(
'GET',
'http://www.google.com/',
null,
null, array(
205 CURLOPT_RETURNTRANSFER => 0,
207 CURLOPT_CONNECTTIMEOUT => 150,
208 CURLOPT_WRITEFUNCTION =>
'callback',
209 CURLOPT_HEADERFUNCTION =>
'callback',
210 CURLOPT_HTTPHEADER => array(
'Accept:',
'Host: www.google.com',
'User-Agent: ' . $userAgent),
213 array(
'TRACE',
'http://www.google.com/',
null,
null, array(
214 CURLOPT_CUSTOMREQUEST =>
'TRACE'
217 array(
'GET',
'http://127.0.0.1:8080',
null,
null, array(
218 CURLOPT_RETURNTRANSFER => 0,
220 CURLOPT_CONNECTTIMEOUT => 150,
221 CURLOPT_WRITEFUNCTION =>
'callback',
222 CURLOPT_HEADERFUNCTION =>
'callback',
223 CURLOPT_PORT => 8080,
224 CURLOPT_HTTPHEADER => array(
'Accept:',
'Host: 127.0.0.1:8080',
'User-Agent: ' . $userAgent),
227 array(
'HEAD',
'http://www.google.com/',
null,
null, array(
228 CURLOPT_RETURNTRANSFER => 0,
230 CURLOPT_CONNECTTIMEOUT => 150,
231 CURLOPT_HEADERFUNCTION =>
'callback',
232 CURLOPT_HTTPHEADER => array(
'Accept:',
'Host: www.google.com',
'User-Agent: ' . $userAgent),
236 array(
'GET',
'https://michael:123@127.0.0.1/index.html?q=2',
null,
null, array(
237 CURLOPT_RETURNTRANSFER => 0,
239 CURLOPT_CONNECTTIMEOUT => 150,
240 CURLOPT_WRITEFUNCTION =>
'callback',
241 CURLOPT_HEADERFUNCTION =>
'callback',
242 CURLOPT_HTTPHEADER => array(
245 'Authorization: Basic ' . $auth,
246 'User-Agent: ' . $userAgent
251 array(
'GET',
'http://127.0.0.1:8124/', array(
252 'x-test-data' =>
'Guzzle'
254 CURLOPT_PORT => 8124,
255 CURLOPT_HTTPHEADER => array(
257 'Host: 127.0.0.1:8124',
258 'x-test-data: Guzzle',
259 'User-Agent: ' . $userAgent
264 'x-test-data' =>
'Guzzle'
267 array(
'POST',
'http://127.0.0.1:8124/post.php',
null, $qs, array(
268 CURLOPT_RETURNTRANSFER => 0,
270 CURLOPT_CONNECTTIMEOUT => 150,
271 CURLOPT_WRITEFUNCTION =>
'callback',
272 CURLOPT_HEADERFUNCTION =>
'callback',
273 CURLOPT_POSTFIELDS =>
'x=y&z=a',
274 CURLOPT_HTTPHEADER => array (
277 'Host: 127.0.0.1:8124',
278 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
279 'User-Agent: ' . $userAgent
284 'Content-Length' =>
'7',
286 'Content-Type' =>
'application/x-www-form-urlencoded; charset=utf-8',
287 '!Transfer-Encoding' =>
null
290 array(
'PUT',
'http://127.0.0.1:8124/put.php',
null,
EntityBody::factory(fopen($testFile,
'r+')), array(
291 CURLOPT_RETURNTRANSFER => 0,
293 CURLOPT_CONNECTTIMEOUT => 150,
294 CURLOPT_WRITEFUNCTION =>
'callback',
295 CURLOPT_HEADERFUNCTION =>
'callback',
296 CURLOPT_READFUNCTION =>
'callback',
297 CURLOPT_INFILESIZE => filesize($testFile),
298 CURLOPT_HTTPHEADER => array (
301 'Host: 127.0.0.1:8124',
302 'User-Agent: ' . $userAgent
308 'Content-Length' => $testFileSize,
309 '!Transfer-Encoding' =>
null
312 array(
'POST',
'http://127.0.0.1:8124/post.php',
null, array(
316 CURLOPT_RETURNTRANSFER => 0,
318 CURLOPT_CONNECTTIMEOUT => 150,
319 CURLOPT_WRITEFUNCTION =>
'callback',
320 CURLOPT_HEADERFUNCTION =>
'callback',
322 CURLOPT_POSTFIELDS =>
'x=y&a=b',
323 CURLOPT_HTTPHEADER => array (
326 'Host: 127.0.0.1:8124',
327 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
328 'User-Agent: ' . $userAgent
333 'Content-Length' =>
'7',
335 'Content-Type' =>
'application/x-www-form-urlencoded; charset=utf-8',
336 '!Transfer-Encoding' =>
null
339 array(
'POST',
'http://127.0.0.1:8124/post.php', array(
340 'Content-Type' =>
'application/json'
341 ),
'{"hi":"there"}', array(
342 CURLOPT_RETURNTRANSFER => 0,
344 CURLOPT_CONNECTTIMEOUT => 150,
345 CURLOPT_WRITEFUNCTION =>
'callback',
346 CURLOPT_HEADERFUNCTION =>
'callback',
347 CURLOPT_CUSTOMREQUEST =>
'POST',
348 CURLOPT_UPLOAD =>
true,
349 CURLOPT_INFILESIZE => 14,
350 CURLOPT_HTTPHEADER => array (
353 'Host: 127.0.0.1:8124',
354 'Content-Type: application/json',
355 'User-Agent: ' . $userAgent
360 'Content-Type' =>
'application/json',
362 'Content-Length' =>
'14',
363 '!Transfer-Encoding' =>
null
366 array(
'POST',
'http://127.0.0.1:8124/post.php', array(
367 'Content-Type' =>
'application/json',
368 'Transfer-Encoding' =>
'chunked'
369 ),
'{"hi":"there"}', array(
370 CURLOPT_RETURNTRANSFER => 0,
372 CURLOPT_CONNECTTIMEOUT => 150,
373 CURLOPT_WRITEFUNCTION =>
'callback',
374 CURLOPT_HEADERFUNCTION =>
'callback',
375 CURLOPT_CUSTOMREQUEST =>
'POST',
376 CURLOPT_UPLOAD =>
true,
377 CURLOPT_HTTPHEADER => array (
380 'Host: 127.0.0.1:8124',
381 'Transfer-Encoding: chunked',
382 'Content-Type: application/json',
383 'User-Agent: ' . $userAgent
388 'Content-Type' =>
'application/json',
390 'Transfer-Encoding' =>
'chunked',
391 '!Content-Length' =>
''
394 array(
'POST',
'http://127.0.0.1:8124/post.php',
null,
'', array(
395 CURLOPT_CUSTOMREQUEST =>
'POST',
396 CURLOPT_HTTPHEADER => array (
399 'Host: 127.0.0.1:8124',
400 'User-Agent: ' . $userAgent
405 'Content-Length' =>
'0',
406 '!Transfer-Encoding' =>
null
409 array(
'POST',
'http://127.0.0.1:8124/post.php',
null, array(), array(
410 CURLOPT_CUSTOMREQUEST =>
'POST',
411 CURLOPT_HTTPHEADER => array (
414 'Host: 127.0.0.1:8124',
415 'User-Agent: ' . $userAgent
420 'Content-Length' =>
'0',
421 '!Transfer-Encoding' =>
null
424 array(
'PATCH',
'http://127.0.0.1:8124/patch.php',
null,
'body', array(
425 CURLOPT_INFILESIZE => 4,
426 CURLOPT_HTTPHEADER => array (
429 'Host: 127.0.0.1:8124',
430 'User-Agent: ' . $userAgent
434 array(
'DELETE',
'http://127.0.0.1:8124/delete.php',
null,
'body', array(
435 CURLOPT_CUSTOMREQUEST =>
'DELETE',
436 CURLOPT_INFILESIZE => 4,
437 CURLOPT_HTTPHEADER => array (
440 'Host: 127.0.0.1:8124',
441 'User-Agent: ' . $userAgent
446 'Content-Length' =>
'4',
448 '!Transfer-Encoding' =>
null
458 array(
'GET',
'http://www.google.com#head',
null,
null, array(
459 CURLOPT_RETURNTRANSFER => 0,
461 CURLOPT_CONNECTTIMEOUT => 150,
462 CURLOPT_WRITEFUNCTION =>
'callback',
463 CURLOPT_HEADERFUNCTION =>
'callback',
464 CURLOPT_HTTPHEADER => array(
'Accept:',
'Host: www.google.com',
'User-Agent: ' . $userAgent),
468 $postTest = array(
'POST',
'http://127.0.0.1:8124/post.php',
null, $postBody, array(
469 CURLOPT_RETURNTRANSFER => 0,
471 CURLOPT_CONNECTTIMEOUT => 150,
472 CURLOPT_WRITEFUNCTION =>
'callback',
473 CURLOPT_HEADERFUNCTION =>
'callback',
475 CURLOPT_POSTFIELDS => array(
476 'file' =>
'@' . $testFile .
';filename=phpunit.xml.dist;type=application/octet-stream'
478 CURLOPT_HTTPHEADER => array (
480 'Host: 127.0.0.1:8124',
481 'Content-Type: multipart/form-data',
482 'Expect: 100-Continue',
483 'User-Agent: ' . $userAgent
488 'Content-Length' =>
'*',
489 'Expect' =>
'100-Continue',
490 'Content-Type' =>
'multipart/form-data; boundary=*',
491 '!Transfer-Encoding' =>
null
494 if (version_compare(phpversion(),
'5.5.0',
'>=')) {
495 $postTest[4][CURLOPT_POSTFIELDS] = array(
496 'file' =>
new \CurlFile($testFile,
'application/octet-stream',
'phpunit.xml.dist')
500 $tests[] = $postTest;
511 $request = $client->createRequest($method, $url, $headers, $body);
512 $request->getCurlOptions()->set(
'debug',
true);
514 $originalRequest = clone $request;
515 $curlTest = clone $request;
518 $this->assertInstanceOf(
'Guzzle\\Http\\Curl\\CurlHandle', $handle);
519 $o = $handle->getOptions()->getAll();
522 if (isset($o[CURLOPT_HTTPHEADER])) {
523 $o[CURLOPT_HTTPHEADER] = array_map(
'strtolower', $o[CURLOPT_HTTPHEADER]);
525 if (isset($options[CURLOPT_HTTPHEADER])) {
526 $options[CURLOPT_HTTPHEADER] = array_map(
'strtolower', $options[CURLOPT_HTTPHEADER]);
530 foreach ($options as $key => $value) {
532 $this->assertArrayHasKey($key, $o,
'-> Check number ' . $check);
533 if ($key != CURLOPT_HTTPHEADER && $key != CURLOPT_POSTFIELDS && (is_array($o[$key])) || $o[$key] instanceof \Closure) {
534 $this->assertEquals(
'callback', $value,
'-> Check number ' . $check);
536 $this->assertTrue($value == $o[$key],
'-> Check number ' . $check .
' - ' . var_export($value,
true) .
' != ' . var_export($o[$key],
true));
541 if ($expectedHeaders) {
545 $request->setClient($client);
547 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
551 $requests = $this->
getServer()->getReceivedRequests(
true);
552 $this->assertEquals($method, $requests[0]->getMethod());
554 $test = $this->
compareHeaders($expectedHeaders, $requests[0]->getHeaders());
555 $this->assertFalse($test, $test .
"\nSent: \n" . $request .
"\n\n" . $requests[0]);
558 if ($request->getHeader(
'Content-Length')) {
559 $this->assertEquals((
string) $request->getHeader(
'Content-Length'), (
string) $requests[0]->getHeader(
'Content-Length'));
567 $request->setProtocolVersion(
'1.1');
569 $options = $handle->getOptions();
570 $this->assertEquals(CURL_HTTP_VERSION_1_1, $options[CURLOPT_HTTP_VERSION]);
576 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
579 $request = $client->put(
'/');
580 $request->getCurlOptions()->set(
'debug',
true);
582 $request->getCurlOptions()->set(
'progress',
true);
588 $this->assertTrue($o->has(
'curl.callback.progress'));
591 $r = $this->
getServer()->getReceivedRequests(
true);
592 $this->assertFalse($r[0]->hasHeader(
'Transfer-Encoding'));
593 $this->assertEquals(4, (
string) $r[0]->getHeader(
'Content-Length'));
594 $sent = strtolower($r[0]);
595 $this->assertContains(
'put / http/1.1', $sent);
596 $this->assertContains(
'host: 127.0.0.1', $sent);
597 $this->assertContains(
'user-agent:', $sent);
598 $this->assertContains(
'content-type: text/plain', $sent);
605 "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
606 "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi"
609 $request = $client->put(
'/');
613 $r = $this->
getServer()->getReceivedRequests(
true);
614 $this->assertEquals(
'chunked', $r[1]->getHeader(
'Transfer-Encoding'));
615 $this->assertFalse($r[1]->hasHeader(
'Content-Length'));
621 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
624 $request = $client->put(
'/', array(
'Transfer-Encoding' =>
'chunked'),
'hi!');
627 $r = $this->
getServer()->getReceivedRequests(
true);
628 $this->assertEquals(
'chunked', $r[0]->getHeader(
'Transfer-Encoding'));
629 $this->assertFalse($r[0]->hasHeader(
'Content-Length'));
630 $this->assertEquals(
'hi!', $r[0]->getBody(
true));
636 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
639 $request->getCurlOptions()->set(
'debug',
true);
640 $request->setClient(
new Client());
641 $request->addPostFields(array(
643 'c' =>
'ay! ~This is a test, isn\'t it?'
648 $r = $this->
getServer()->getReceivedRequests(
true);
649 $this->assertEquals(
'a=b&c=ay%21%20~This%20is%20a%20test%2C%20isn%27t%20it%3F', (
string) $r[0]->getBody());
650 $this->assertFalse($r[0]->hasHeader(
'Transfer-Encoding'));
651 $this->assertEquals(56, (
string) $r[0]->getHeader(
'Content-Length'));
652 $sent = strtolower($r[0]);
653 $this->assertContains(
'post / http/1.1', $sent);
654 $this->assertContains(
'content-type: application/x-www-form-urlencoded; charset=utf-8', $sent);
660 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
663 $request->getCurlOptions()->set(
'debug',
true);
664 $request->setClient(
new Client());
665 $request->addPostFiles(array(
668 $request->addPostFields(array(
670 'arr' => array(
'a' => 1,
'b' => 2),
676 $options = $this->requestHandle->getOptions()->getAll();
677 if (version_compare(phpversion(),
'5.5.0',
'<')) {
678 $this->assertContains(
'@' . __FILE__ .
';filename=CurlHandleTest.php;type=text/x-', $options[CURLOPT_POSTFIELDS][
'foo']);
680 $this->assertInstanceOf(
'CURLFile', $options[CURLOPT_POSTFIELDS][
'foo']);
682 $this->assertEquals(
'baz', $options[CURLOPT_POSTFIELDS][
'bar']);
683 $this->assertEquals(
'1', $options[CURLOPT_POSTFIELDS][
'arr[a]']);
684 $this->assertEquals(
'2', $options[CURLOPT_POSTFIELDS][
'arr[b]']);
686 $this->assertTrue($request->hasHeader(
'Content-Length'));
692 $request->setClient(
new Client(
'http://www.example.com'));
693 $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT, 99);
694 $request->getCurlOptions()->set(
'curl.fake_opt', 99);
695 $request->getCurlOptions()->set(CURLOPT_PORT, 8181);
697 $this->assertEquals(99, $handle->getOptions()->get(CURLOPT_CONNECTTIMEOUT));
698 $this->assertEquals(8181, $handle->getOptions()->get(CURLOPT_PORT));
699 $this->assertNull($handle->getOptions()->get(
'curl.fake_opt'));
700 $this->assertNull($handle->getOptions()->get(
'fake_opt'));
707 $handle->updateRequestFromTransfer($request);
713 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
715 $request = $client->put(
'/',
null,
'foo');
716 $request->getCurlOptions()->set(
'body_as_string',
true);
718 $requests = $this->
getServer()->getReceivedRequests(
false);
719 $this->assertContains(
'PUT /', $requests[0]);
720 $this->assertContains(
"\nfoo", $requests[0]);
721 $this->assertContains(
'content-length: 3', $requests[0]);
722 $this->assertNotContains(
'content-type', $requests[0]);
728 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
730 $request = $client->post(
'/',
null,
'foo');
731 $request->getCurlOptions()->set(
'body_as_string',
true);
733 $requests = $this->
getServer()->getReceivedRequests(
false);
734 $this->assertContains(
'POST /', $requests[0]);
735 $this->assertContains(
"\nfoo", $requests[0]);
736 $this->assertContains(
'content-length: 3', $requests[0]);
737 $this->assertNotContains(
'content-type', $requests[0]);
743 $request->getCurlOptions()->set(
'debug',
true);
745 $this->assertNotNull($handle->getOptions()->get(CURLOPT_STDERR));
746 $this->assertNotNull($handle->getOptions()->get(CURLOPT_VERBOSE));
752 $request->getCurlOptions()->set(CURLOPT_TIMEOUT, 200);
754 $this->assertEquals(200, $handle->getOptions()->get(CURLOPT_TIMEOUT));
760 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
762 $fileToUpload = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR .
'TestData' . DIRECTORY_SEPARATOR .
'test_service.json';
765 $request = $client->post();
766 $request->addPostFile(
'foo', $fileToUpload,
'application/json');
767 $request->addPostFile(
'foo', __FILE__);
770 $requests = $this->
getServer()->getReceivedRequests(
true);
771 $body = (string) $requests[0]->getBody();
773 $this->assertContains(
'Content-Disposition: form-data; name="foo[0]"; filename="', $body);
774 $this->assertContains(
'Content-Type: application/json', $body);
775 $this->assertContains(
'Content-Type: text/x-', $body);
776 $this->assertContains(
'Content-Disposition: form-data; name="foo[1]"; filename="', $body);
781 return array(array(
'POST'), array(
'PUT'), array(
'PATCH'));
790 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
792 $client->createRequest($method)->send();
793 $requests = $this->
getServer()->getReceivedRequests(
true);
794 $this->assertFalse($requests[0]->hasHeader(
'Transfer-Encoding'));
795 $this->assertTrue($requests[0]->hasHeader(
'Content-Length'));
796 $this->assertEquals(
'0', (
string) $requests[0]->getHeader(
'Content-Length'));
805 $this->assertEquals($expected, $actual);
819 'CURLOPT_PORT' => 10,
820 'CURLOPT_TIMEOUT' => 99
824 CURLOPT_TIMEOUT => 99
829 array(
'debug' =>
true),
830 array(
'debug' =>
true)
834 array(
'debug' =>
'CURLPROXY_HTTP'),
835 array(
'debug' => CURLPROXY_HTTP)
844 "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
845 "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
849 $request = $client->put(
'/',
null,
'test');
853 $received = $this->
getServer()->getReceivedRequests(
true);
854 $this->assertEquals(2, count($received));
855 $this->assertEquals(
'test', (
string) $received[0]->getBody());
856 $this->assertEquals(
'test', (
string) $received[1]->getBody());
862 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
865 $request = $client->get(
'/',
null);
866 $request->getCurlOptions()->set(CURLOPT_ENCODING,
'');
869 $options = $this->requestHandle->getOptions()->getAll();
870 $this->assertSame(
'', $options[CURLOPT_ENCODING]);
871 $received = $this->
getServer()->getReceivedRequests(
false);
879 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
881 $request = $client->put(
'/',
null,
'test');
884 $request->setExpectHeaderCutoff(2)->send();
885 $options = $this->requestHandle->getOptions()->getAll();
886 $this->assertContains(
'Expect: 100-Continue', $options[CURLOPT_HTTPHEADER]);
887 $received = $this->
getServer()->getReceivedRequests(
false);
894 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata");
896 $request = $client->get(
'/', array(
897 'Accept' =>
'application/json',
898 'Accept-Encoding' =>
'gzip, deflate',
902 $options = $this->requestHandle->getOptions()->getAll();
903 $this->assertSame(
'gzip, deflate', $options[CURLOPT_ENCODING]);
904 $received = $this->
getServer()->getReceivedRequests(
false);
912 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
915 $request = $client->put($this->
getServer()->getUrl(),
null, array(
921 $requests = $this->
getServer()->getReceivedRequests(
true);
922 $this->assertEquals(
'PUT', $requests[0]->getMethod());
924 'application/x-www-form-urlencoded; charset=utf-8',
925 (
string) $requests[0]->getHeader(
'Content-Type')
927 $this->assertEquals(15, (
string) $requests[0]->getHeader(
'Content-Length'));
928 $this->assertEquals(
'foo=baz&baz=bar', (
string) $requests[0]->getBody());
934 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
937 $request = $client->put($this->
getServer()->getUrl(),
null, array(
938 'foo' =>
'@' . __FILE__
942 $requests = $this->
getServer()->getReceivedRequests(
true);
943 $this->assertEquals(
'PUT', $requests[0]->getMethod());
944 $this->assertContains(
'multipart/form-data', (
string) $requests[0]->getHeader(
'Content-Type'));
945 $this->assertContains(
'testSendsPostFilesForNonPostRequests', (
string) $requests[0]->getBody());