mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-12 03:16:34 +00:00
Fix #303: Add methods for mocking.
Thanks to Sven Lütje (B4rb4ross4) for the initial suggestion and pull request.
This commit is contained in:
@@ -207,12 +207,42 @@ Curl::error($callback)
|
||||
Curl::exec($ch = null)
|
||||
Curl::execDone()
|
||||
Curl::get($url, $data = array())
|
||||
Curl::getAttempts()
|
||||
Curl::getBeforeSendCallback()
|
||||
Curl::getCompleteCallback()
|
||||
Curl::getCookie($key)
|
||||
Curl::getCurl()
|
||||
Curl::getCurlErrorCode()
|
||||
Curl::getCurlErrorMessage()
|
||||
Curl::getDownloadCompleteCallback()
|
||||
Curl::getErrorCallback()
|
||||
Curl::getErrorCode()
|
||||
Curl::getErrorMessage()
|
||||
Curl::getFileHandle()
|
||||
Curl::getHttpErrorMessage()
|
||||
Curl::getHttpStatusCode()
|
||||
Curl::getId()
|
||||
Curl::getInfo($opt = null)
|
||||
Curl::getJsonDecoder()
|
||||
Curl::getOpt($option)
|
||||
Curl::getRawResponse()
|
||||
Curl::getRawResponseHeaders()
|
||||
Curl::getRemainingRetries()
|
||||
Curl::getRequestHeaders()
|
||||
Curl::getResponse()
|
||||
Curl::getResponseCookie($key)
|
||||
Curl::getResponseCookies()
|
||||
Curl::getResponseHeaders()
|
||||
Curl::getRetries()
|
||||
Curl::getRetryDecider()
|
||||
Curl::getSuccessCallback()
|
||||
Curl::getUrl()
|
||||
Curl::getXmlDecoder()
|
||||
Curl::head($url, $data = array())
|
||||
Curl::isChildOfMultiCurl()
|
||||
Curl::isCurlError()
|
||||
Curl::isError()
|
||||
Curl::isHttpError()
|
||||
Curl::options($url, $data = array())
|
||||
Curl::patch($url, $data = array())
|
||||
Curl::post($url, $data = '', $follow_303_with_post = false)
|
||||
|
||||
+156
-13
@@ -396,7 +396,7 @@ class Curl
|
||||
$this->setOpt(CURLOPT_NOBODY, false);
|
||||
|
||||
// Allow multicurl to attempt retry as needed.
|
||||
if ($this->childOfMultiCurl) {
|
||||
if ($this->isChildOfMultiCurl()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -741,18 +741,6 @@ class Curl
|
||||
return isset($this->responseCookies[$key]) ? $this->responseCookies[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Response Cookies
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseCookies()
|
||||
{
|
||||
return $this->responseCookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Max Filesize
|
||||
*
|
||||
@@ -1211,6 +1199,161 @@ class Curl
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
public function getCurl()
|
||||
{
|
||||
return $this->curl;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function isError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
public function isCurlError()
|
||||
{
|
||||
return $this->curlError;
|
||||
}
|
||||
|
||||
public function getCurlErrorCode()
|
||||
{
|
||||
return $this->curlErrorCode;
|
||||
}
|
||||
|
||||
public function getCurlErrorMessage()
|
||||
{
|
||||
return $this->curlErrorMessage;
|
||||
}
|
||||
|
||||
public function isHttpError()
|
||||
{
|
||||
return $this->httpError;
|
||||
}
|
||||
|
||||
public function getHttpStatusCode()
|
||||
{
|
||||
return $this->httpStatusCode;
|
||||
}
|
||||
|
||||
public function getHttpErrorMessage()
|
||||
{
|
||||
return $this->httpErrorMessage;
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function getRequestHeaders()
|
||||
{
|
||||
return $this->requestHeaders;
|
||||
}
|
||||
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
public function getRawResponseHeaders()
|
||||
{
|
||||
return $this->rawResponseHeaders;
|
||||
}
|
||||
|
||||
public function getResponseCookies()
|
||||
{
|
||||
return $this->responseCookies;
|
||||
}
|
||||
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function getRawResponse()
|
||||
{
|
||||
return $this->rawResponse;
|
||||
}
|
||||
|
||||
public function getBeforeSendCallback()
|
||||
{
|
||||
return $this->beforeSendCallback;
|
||||
}
|
||||
|
||||
public function getDownloadCompleteCallback()
|
||||
{
|
||||
return $this->downloadCompleteCallback;
|
||||
}
|
||||
|
||||
public function getSuccessCallback()
|
||||
{
|
||||
return $this->successCallback;
|
||||
}
|
||||
|
||||
public function getErrorCallback()
|
||||
{
|
||||
return $this->errorCallback;
|
||||
}
|
||||
|
||||
public function getCompleteCallback()
|
||||
{
|
||||
return $this->completeCallback;
|
||||
}
|
||||
|
||||
public function getFileHandle()
|
||||
{
|
||||
return $this->fileHandle;
|
||||
}
|
||||
|
||||
public function getAttempts()
|
||||
{
|
||||
return $this->attempts;
|
||||
}
|
||||
|
||||
public function getRetries()
|
||||
{
|
||||
return $this->retries;
|
||||
}
|
||||
|
||||
public function isChildOfMultiCurl()
|
||||
{
|
||||
return $this->childOfMultiCurl;
|
||||
}
|
||||
|
||||
public function getRemainingRetries()
|
||||
{
|
||||
return $this->remainingRetries;
|
||||
}
|
||||
|
||||
public function getRetryDecider()
|
||||
{
|
||||
return $this->retryDecider;
|
||||
}
|
||||
|
||||
public function getJsonDecoder()
|
||||
{
|
||||
return $this->jsonDecoder;
|
||||
}
|
||||
|
||||
public function getXmlDecoder()
|
||||
{
|
||||
return $this->xmlDecoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destruct
|
||||
*
|
||||
|
||||
@@ -3676,4 +3676,16 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
$user_agent = $test->server('server', 'GET', array('key' => 'HTTP_USER_AGENT'));
|
||||
$this->assertEquals($original_user_agent, $user_agent);
|
||||
}
|
||||
|
||||
public function testMock()
|
||||
{
|
||||
$curl = $this->getMockBuilder('Curl\Curl')
|
||||
->getMock();
|
||||
|
||||
$curl->expects($this->once())
|
||||
->method('getRawResponse')
|
||||
->will($this->returnValue('[]'));
|
||||
|
||||
$this->assertEquals('[]', $curl->getRawResponse());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user