Merge pull request #408 from zachborboa/master

Allow calling Curl::getInfo() without option
This commit is contained in:
Zach Borboa
2016-11-04 21:27:04 -07:00
committed by GitHub
3 changed files with 67 additions and 3 deletions
+1 -1
View File
@@ -201,7 +201,7 @@ Curl::error($callback)
Curl::exec($ch = null)
Curl::get($url, $data = array())
Curl::getCookie($key)
Curl::getInfo($opt)
Curl::getInfo($opt = null)
Curl::getOpt($option)
Curl::getResponseCookie($key)
Curl::head($url, $data = array())
+9 -2
View File
@@ -422,9 +422,16 @@ class Curl
*
* @return mixed
*/
public function getInfo($opt)
public function getInfo($opt = null)
{
return curl_getinfo($this->curl, $opt);
$args = array();
$args[] = $this->curl;
if (func_num_args()) {
$args[] = $opt;
}
return call_user_func_array('curl_getinfo', $args);
}
/**
+57
View File
@@ -3000,4 +3000,61 @@ class CurlTest extends PHPUnit_Framework_TestCase
$curl->get(Test::TEST_URL, $data);
$this->assertEquals('', $curl->response);
}
public function testGetInfo()
{
$test = new Test();
$test->server('server', 'GET');
$info = $test->curl->getInfo();
$expected_keys = array(
'url',
'content_type',
'http_code',
'header_size',
'request_size',
'filetime',
'ssl_verify_result',
'redirect_count',
'total_time',
'namelookup_time',
'connect_time',
'pretransfer_time',
'size_upload',
'size_download',
'speed_download',
'speed_upload',
'download_content_length',
'upload_content_length',
'starttransfer_time',
'redirect_time',
'certinfo',
'primary_ip',
'primary_port',
'local_ip',
'local_port',
'redirect_url',
'request_header',
);
// Not all keys are included on PHP 5.3 (tested 5.3.29).
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
foreach (array('primary_ip', 'primary_port', 'local_ip', 'local_port') as $value) {
$key = array_search($value, $expected_keys);
unset($expected_keys[$key]);
}
}
// Not all keys are included on HHVM (tested 3.6.6).
if (defined('HHVM_VERSION')) {
foreach (array('certinfo', 'primary_ip', 'primary_port', 'local_ip', 'redirect_url') as $value) {
$key = array_search($value, $expected_keys);
unset($expected_keys[$key]);
}
}
foreach ($expected_keys as $key) {
$this->assertArrayHasKey($key, $info);
}
}
}