diff --git a/README.md b/README.md index a86017f..461ecb3 100644 --- a/README.md +++ b/README.md @@ -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()) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index a8e31a5..47c4914 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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); } /** diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index ec7d81e..0ee82a6 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -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); + } + } }