From cdad9e1a0191e6626f628c7f864f6d89feabab82 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 7 Jul 2018 03:59:46 -0700 Subject: [PATCH 1/3] Rename variable to use isChildOfMultiCurl as method name --- src/Curl/Curl.php | 4 ++-- src/Curl/MultiCurl.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 67435f3..a780e24 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -42,7 +42,7 @@ class Curl public $attempts = 0; public $retries = 0; - public $isChildOfMultiCurl = false; + public $childOfMultiCurl = false; public $remainingRetries = 0; public $retryDecider = null; @@ -396,7 +396,7 @@ class Curl $this->setOpt(CURLOPT_NOBODY, false); // Allow multicurl to attempt retry as needed. - if ($this->isChildOfMultiCurl) { + if ($this->childOfMultiCurl) { return; } diff --git a/src/Curl/MultiCurl.php b/src/Curl/MultiCurl.php index 05c1170..b597df6 100644 --- a/src/Curl/MultiCurl.php +++ b/src/Curl/MultiCurl.php @@ -812,7 +812,7 @@ class MultiCurl { // Use sequential ids to allow for ordered post processing. $curl->id = $this->nextCurlId++; - $curl->isChildOfMultiCurl = true; + $curl->childOfMultiCurl = true; $this->curls[$curl->id] = $curl; $curl->setHeaders($this->headers); From c21970ff9ab7415f34e69f932fc1cf099f924edb Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 7 Jul 2018 04:16:34 -0700 Subject: [PATCH 2/3] Fix #303: Add methods for mocking. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Sven Lütje (B4rb4ross4) for the initial suggestion and pull request. --- README.md | 30 +++++ src/Curl/Curl.php | 169 ++++++++++++++++++++++-- tests/PHPCurlClass/PHPCurlClassTest.php | 12 ++ 3 files changed, 198 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7a3a6d0..8ee9b78 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index a780e24..20b3f8f 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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 * diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 3d3cc90..d7e4ca6 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -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()); + } } From c5db809662b8441c27badcf68b7892d3601fb418 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 7 Jul 2018 04:29:21 -0700 Subject: [PATCH 3/3] Allow tests to have mock-style indentation --- tests/script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script.sh b/tests/script.sh index f5e7387..1282852 100755 --- a/tests/script.sh +++ b/tests/script.sh @@ -63,7 +63,7 @@ EOF # Skip hhvm "Notice: File could not be loaded: ..." if [[ "${TRAVIS_PHP_VERSION}" != "hhvm" ]] && [[ "${TRAVIS_PHP_VERSION}" != "hhvm-nightly" ]]; then export -f "find_invalid_indentation" - invalid_indentation=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;) + invalid_indentation=$(find . -type "f" -iname "*.php" ! -path "*/tests/*" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;) if [[ ! -z "${invalid_indentation}" ]]; then echo "${invalid_indentation}" ((errors++))