From f3ad85addda220b09b87d98aba1a2d527655f71a Mon Sep 17 00:00:00 2001 From: Syl Date: Tue, 20 May 2014 14:20:25 +0200 Subject: [PATCH] refactor and renamed to php-curl --- .gitignore | 4 +- .travis.yml | 8 +- LICENSE | 0 README.md | 4 +- composer.json | 20 +-- composer.lock | 14 +- phpunit.xml.dist | 8 +- src/RESTClient.php | 250 ----------------------------------- src/sylouuu/Curl/Curl.php | 160 ++++++++++++++++++++++ src/sylouuu/Curl/Delete.php | 34 +++++ src/sylouuu/Curl/Get.php | 30 +++++ src/sylouuu/Curl/Head.php | 35 +++++ src/sylouuu/Curl/Options.php | 34 +++++ src/sylouuu/Curl/Patch.php | 42 ++++++ src/sylouuu/Curl/Post.php | 39 ++++++ src/sylouuu/Curl/Put.php | 42 ++++++ tests/CurlRequestTest.php | 202 ++++++++++++++++++++++++++++ tests/CurlTest.php | 97 ++++++++++++++ tests/RESTClientTest.php | 127 ------------------ 19 files changed, 750 insertions(+), 400 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .travis.yml mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 composer.json mode change 100644 => 100755 composer.lock mode change 100644 => 100755 phpunit.xml.dist delete mode 100644 src/RESTClient.php create mode 100644 src/sylouuu/Curl/Curl.php create mode 100644 src/sylouuu/Curl/Delete.php create mode 100644 src/sylouuu/Curl/Get.php create mode 100644 src/sylouuu/Curl/Head.php create mode 100644 src/sylouuu/Curl/Options.php create mode 100644 src/sylouuu/Curl/Patch.php create mode 100644 src/sylouuu/Curl/Post.php create mode 100644 src/sylouuu/Curl/Put.php create mode 100755 tests/CurlRequestTest.php create mode 100644 tests/CurlTest.php delete mode 100644 tests/RESTClientTest.php diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index a725465..0420048 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -vendor/ \ No newline at end of file +node_modules/ +vendor/ +.DS_Store diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 index 3cf4207..ec05105 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,12 @@ language: php php: - 5.4 - 5.5 + - 5.6 + - hhvm + +matrix: + allow_failures: + - php: hhvm before_script: - composer self-update @@ -12,4 +18,4 @@ script: - phpunit notifications: - email: false \ No newline at end of file + email: false diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 78f89ac..184a4e1 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP REST Client [![Build Status](https://travis-ci.org/sylouuu/php-rest-client.svg)](https://travis-ci.org/sylouuu/php-rest-client) [![GitHub version](https://badge.fury.io/gh/sylouuu%2Fphp-rest-client.svg)](http://badge.fury.io/gh/sylouuu%2Fphp-rest-client) +# PHP cURL [![Build Status](https://travis-ci.org/sylouuu/php-curl.svg)](https://travis-ci.org/sylouuu/php-curl) [![GitHub version](https://badge.fury.io/gh/sylouuu%2Fphp-curl.svg)](http://badge.fury.io/gh/sylouuu%2Fphp-curl) [![devDependency Status](https://david-dm.org/sylouuu/php-curl/dev-status.svg?theme=shields.io)](https://david-dm.org/sylouuu/php-curl#info=devDependencies) ## Requirements @@ -12,7 +12,7 @@ ```js { "require": { - "sylouuu/php-rest-client": "0.4.*" + "sylouuu/php-curl": "0.5.*" } } ``` diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index fd9a2b6..9649b90 --- a/composer.json +++ b/composer.json @@ -1,19 +1,23 @@ { - "name": "sylouuu/php-rest-client", + "name": "sylouuu/php-curl", "description": "Lightweight PHP cURL wrapper", "type": "library", - "keywords": [ - "rest", - "http", - "api" - ], + "keywords": ["curl", "http"], "minimum-stability": "stable", - "homepage": "https://github.com/sylouuu/php-rest-client", + "homepage": "https://github.com/sylouuu/php-curl", "license": "MIT", "support": { - "issues": "https://github.com/sylouuu/php-rest-client/issues" + "issues": "https://github.com/sylouuu/php-curl/issues" }, "require": { + "php": ">5.3.0" + }, + "require-dev": { "phpunit/phpunit": "4.0.*" + }, + "autoload": { + "psr-0": { + "sylouuu\\Curl": "src/" + } } } diff --git a/composer.lock b/composer.lock old mode 100644 new mode 100755 index f4f1934..af06a32 --- a/composer.lock +++ b/composer.lock @@ -3,8 +3,11 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "c9eb94eb6acb513535c3a1e999114cb5", + "hash": "9e4d6dbbecd657a4e9da8a87b56b4be2", "packages": [ + + ], + "packages-dev": [ { "name": "phpunit/php-code-coverage", "version": "2.0.6", @@ -634,9 +637,6 @@ "homepage": "http://symfony.com", "time": "2014-04-18 20:37:09" } - ], - "packages-dev": [ - ], "aliases": [ @@ -645,9 +645,9 @@ "stability-flags": [ ], - "platform": [ - - ], + "platform": { + "php": ">5.3.0" + }, "platform-dev": [ ] diff --git a/phpunit.xml.dist b/phpunit.xml.dist old mode 100644 new mode 100755 index 87c93cb..d55fbdc --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,8 @@ - + - - ./tests/RESTClientTest.php + + ./tests - \ No newline at end of file + diff --git a/src/RESTClient.php b/src/RESTClient.php deleted file mode 100644 index ccad1e3..0000000 --- a/src/RESTClient.php +++ /dev/null @@ -1,250 +0,0 @@ -status; - } - - /** - * Getter HTTP header - * - * @return string - */ - public function getHeader() { - return $this->header; - } - - /** - * Getter response - * - * @return mixed - */ - public function getResponse() { - return $this->response; - } - - /** - * GET request - * - * @param array $options - * - * @return mixed $this - */ - public function head($options) { - // Init cURL - $handle = curl_init($options['url']); - - // Options - curl_setopt($handle, CURLOPT_HEADER, true); - curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'HEAD'); - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * OPTIONS request - * - * @param array $options - * - * @return mixed $this - */ - public function options($options) { - // Init cURL - $handle = curl_init($options['url']); - - // Options - curl_setopt($handle, CURLOPT_HEADER, true); - curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'OPTIONS'); - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * GET request - * - * @param array $options - * - * @return mixed $this - */ - public function get($options) { - // Init cURL - $handle = curl_init($options['url']); - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * POST request - * - * @param array $options - * - * @return mixed $this - */ - public function post($options) { - // Init cURL - $handle = curl_init($options['url']); - - if(isset($options['data'])) { - // Options - curl_setopt($handle, CURLOPT_POSTFIELDS, $options['data']); - curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'POST'); - } else { - throw new \InvalidArgumentException('No data provided for that POST request'); - } - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * PUT request - * - * @param array $options - * - * @return mixed $this - */ - public function put($options) { - // Init cURL - $handle = curl_init($options['url']); - - if(isset($options['data'])) { - // Converting array to an URL-encoded query string - $options['data'] = http_build_query($options['data'], '', '&'); - - // Options - curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($handle, CURLOPT_POSTFIELDS, $options['data']); - } else { - throw new \InvalidArgumentException('No data provided for that PUT request'); - } - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * PATCH request - * - * @param array $options - * - * @return mixed $this - */ - public function patch($options) { - // Init cURL - $handle = curl_init($options['url']); - - if(isset($options['data'])) { - // Converting array to an URL-encoded query string - $options['data'] = http_build_query($options['data'], '', '&'); - - // Options - curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PATCH'); - curl_setopt($handle, CURLOPT_POSTFIELDS, $options['data']); - } else { - throw new \InvalidArgumentException('No data provided for that PATCH request'); - } - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * DELETE request - * - * @param array $options - * - * @return mixed $this - */ - public function delete($options) { - // Init cURL - $handle = curl_init($options['url']); - - // Options - curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE'); - - // Setting response - $this->response = $this->process($handle, $options); - - return $this; - } - - /** - * Processes the request - * - * @param object $handle - * @param array $options - * - * @return mixed $response - */ - private function process($handle, $options) { - // Options - curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); - curl_setopt($handle, CURLINFO_HEADER_OUT, true); - - // Additional headers - if(isset($options['headers']) && count($options['headers']) > 0) { - curl_setopt($handle, CURLOPT_HTTPHEADER, $options['headers']); - } - - // SSL - if(isset($options['ssl'])) { - curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, true); - curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($handle, CURLOPT_CAINFO, getcwd() . $options['ssl']); - } - - // Result - $response = curl_exec($handle); - - // Retrieving HTTP status code - $this->status = curl_getinfo($handle, CURLINFO_HTTP_CODE); - - // Retrieving HTTP header - $this->header = curl_getinfo($handle, CURLINFO_HEADER_OUT); - - // Closing handle - curl_close($handle); - - return $response; - } - - } - -?> \ No newline at end of file diff --git a/src/sylouuu/Curl/Curl.php b/src/sylouuu/Curl/Curl.php new file mode 100644 index 0000000..d25f54c --- /dev/null +++ b/src/sylouuu/Curl/Curl.php @@ -0,0 +1,160 @@ +options = $options; + + // Init cURL + $this->ch = curl_init($options['url']); + } + + /** + * Getter HTTP status code + * + * @return integer + */ + public function getStatus() + { + return $this->status; + } + + /** + * Getter HTTP header + * + * @return string + */ + public function getHeader() + { + return $this->header; + } + + /** + * Getter response + * + * @return mixed + */ + public function getResponse() + { + return $this->response; + } + + /** + * Getter Curl options + * + * @return null|array + */ + public function getCurlOptions() + { + return $this->curl_options; + } + + /** + * Setter Curl option + * + * See options list: http://php.net/manual/en/function.curl-setopt.php + * + * @param const $option + * @param mixed $value + * + * @return mixed + */ + public function setCurlOption($option, $value) + { + curl_setopt($this->ch, $option, $value); + + $this->curl_options[$option] = $value; + + return $this; + } + + /** + * Getter Curl info + * + * See info list: http://php.net/manual/en/function.curl-getinfo.php + * + * @param const $info + * + * @return mixed + */ + public function getCurlInfo($info) + { + return curl_getinfo($this->ch, $info); + } + + /** + * Sends the request + * + * @return $this + */ + public function send() + { + // Default options + $this->setCurlOption(CURLOPT_RETURNTRANSFER, true); + $this->setCurlOption(CURLINFO_HEADER_OUT, true); + + // Additional headers + if(isset($this->options['headers']) && count($this->options['headers']) > 0) { + $this->setCurlOption(CURLOPT_HTTPHEADER, $this->options['headers']); + } + + // SSL + if(isset($options['ssl'])) { + $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, true); + $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 2); + $this->setCurlOption(CURLOPT_CAINFO, getcwd() . $options['ssl']); + } + + // Retrieving HTTP response body + $this->response = curl_exec($this->ch); + + // Retrieving HTTP status code + $this->status = $this->getCurlInfo(CURLINFO_HTTP_CODE); + + // Retrieving HTTP header + $this->header = $this->getCurlInfo(CURLINFO_HEADER_OUT); + + // Autoclose handle + if(!isset($this->options['autoclose']) || (isset($this->options['autoclose']) && $this->options['autoclose'] !== false)) { + $this->close(); + } + + return $this; + } + + /** + * Closes the handle + */ + public function close() { + curl_close($this->ch); + } + + } diff --git a/src/sylouuu/Curl/Delete.php b/src/sylouuu/Curl/Delete.php new file mode 100644 index 0000000..8f2ab24 --- /dev/null +++ b/src/sylouuu/Curl/Delete.php @@ -0,0 +1,34 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() + { + // Options + $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'DELETE'); + } + } diff --git a/src/sylouuu/Curl/Get.php b/src/sylouuu/Curl/Get.php new file mode 100644 index 0000000..9a1e46b --- /dev/null +++ b/src/sylouuu/Curl/Get.php @@ -0,0 +1,30 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() {} + } diff --git a/src/sylouuu/Curl/Head.php b/src/sylouuu/Curl/Head.php new file mode 100644 index 0000000..b929c7f --- /dev/null +++ b/src/sylouuu/Curl/Head.php @@ -0,0 +1,35 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() + { + // Options + $this->setCurlOption(CURLOPT_HEADER, true); + $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'HEAD'); + } + } diff --git a/src/sylouuu/Curl/Options.php b/src/sylouuu/Curl/Options.php new file mode 100644 index 0000000..64ecc75 --- /dev/null +++ b/src/sylouuu/Curl/Options.php @@ -0,0 +1,34 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() + { + // Options + $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'OPTIONS'); + } + } diff --git a/src/sylouuu/Curl/Patch.php b/src/sylouuu/Curl/Patch.php new file mode 100644 index 0000000..87157cd --- /dev/null +++ b/src/sylouuu/Curl/Patch.php @@ -0,0 +1,42 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() + { + if(isset($this->options['data'])) { + // Converting array to an URL-encoded query string + $this->options['data'] = http_build_query($this->options['data'], '', '&'); + + // Options + $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PATCH'); + $this->setCurlOption(CURLOPT_POSTFIELDS, $this->options['data']); + } else { + throw new \InvalidArgumentException('No data provided for that PATCH request'); + } + } + } diff --git a/src/sylouuu/Curl/Post.php b/src/sylouuu/Curl/Post.php new file mode 100644 index 0000000..dd8639c --- /dev/null +++ b/src/sylouuu/Curl/Post.php @@ -0,0 +1,39 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() + { + if(isset($this->options['data'])) { + // Options + $this->setCurlOption(CURLOPT_POSTFIELDS, $this->options['data']); + $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'POST'); + } else { + throw new \InvalidArgumentException('No data provided for that POST request'); + } + } + } diff --git a/src/sylouuu/Curl/Put.php b/src/sylouuu/Curl/Put.php new file mode 100644 index 0000000..95b41ab --- /dev/null +++ b/src/sylouuu/Curl/Put.php @@ -0,0 +1,42 @@ +prepare(); + } + + /** + * Prepare the request + */ + public function prepare() + { + if(isset($this->options['data'])) { + // Converting array to an URL-encoded query string + $this->options['data'] = http_build_query($this->options['data'], '', '&'); + + // Options + $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT'); + $this->setCurlOption(CURLOPT_POSTFIELDS, $this->options['data']); + } else { + throw new \InvalidArgumentException('No data provided for that PUT request'); + } + } + } diff --git a/tests/CurlRequestTest.php b/tests/CurlRequestTest.php new file mode 100755 index 0000000..6389c1c --- /dev/null +++ b/tests/CurlRequestTest.php @@ -0,0 +1,202 @@ +endpoint = 'http://chez-syl.fr/yaapi/api/'; + } + + // Exceptions + // ------------------------------------------------------------------------------------------------------ + + /** + * Standard POST request without data + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage No data provided for that POST request + */ + public function testExceptionPostRequestWithoutData() + { + $request = new \sylouuu\Curl\Post([ + 'url' => $this->endpoint + ]); + } + + /** + * Standard PUT request without data + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage No data provided for that PUT request + */ + public function testExceptionPutRequestWithoutData() + { + $request = new \sylouuu\Curl\Put([ + 'url' => $this->endpoint + ]); + } + + /** + * Standard PATCH request without data + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage No data provided for that PATCH request + */ + public function testExceptionPatchRequestWithoutData() + { + $request = new \sylouuu\Curl\Patch([ + 'url' => $this->endpoint + ]); + } + + // Success + // ------------------------------------------------------------------------------------------------------ + + /** + * Standard OPTIONS request + */ + public function testHeadRequest() + { + $request = new \sylouuu\Curl\Head([ + 'url' => $this->endpoint + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + $this->assertEquals(true, (strpos($request->getResponse(), 'Server') !== false)); + } + + /** + * Standard OPTIONS request + */ + public function testOptionsRequest() + { + $request = new \sylouuu\Curl\Options([ + 'url' => $this->endpoint .'user' + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + $this->assertArrayHasKey('Allow', json_decode($request->getResponse(), true)); + } + + /** + * Standard GET request + */ + public function testGetRequest() + { + $request = new \sylouuu\Curl\Get([ + 'url' => $this->endpoint .'ip' + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + $this->assertArrayHasKey('ip', json_decode($request->getResponse(), true)); + } + + /** + * Standard GET request with specific header + */ + public function testGetRequestWithHeader() + { + $request = new \sylouuu\Curl\Get([ + 'url' => $this->endpoint .'ip', + 'headers' => [ + 'Authorization: foobar' + ] + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + $this->assertEquals(true, (strpos($request->getHeader(), 'Authorization: foobar') !== false)); + } + + /** + * Standard POST request with data + */ + public function testPostRequest() + { + $request = new \sylouuu\Curl\Post([ + 'url' => $this->endpoint .'user', + 'data' => [ + 'name' => 'foo', + 'email' => 'foo@domain.com' + ] + ]); + + $request->send(); + + $this->assertEquals(201, $request->getStatus()); + } + + /** + * Standard PUT request with data + */ + public function testPutRequest() + { + $request = new \sylouuu\Curl\Put([ + 'url' => $this->endpoint .'user/1', + 'data' => [ + 'name' => 'foo' + ] + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + } + + /** + * Standard PATCH request with data + */ + public function testPatchRequest() + { + $request = new \sylouuu\Curl\Patch([ + 'url' => $this->endpoint .'user/1', + 'data' => [ + 'name' => 'foo' + ] + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + } + + /** + * Standard DELETE request + */ + public function testDeleteRequest() + { + $request = new \sylouuu\Curl\Delete([ + 'url' => $this->endpoint .'user/1' + ]); + + $request->send(); + + $this->assertEquals(200, $request->getStatus()); + } + + } diff --git a/tests/CurlTest.php b/tests/CurlTest.php new file mode 100644 index 0000000..25862a2 --- /dev/null +++ b/tests/CurlTest.php @@ -0,0 +1,97 @@ +endpoint = 'http://chez-syl.fr/yaapi/api/'; + } + + /** + * getCurlOptions() + */ + public function testOptionsGetter() + { + $request = new \sylouuu\Curl\Post([ + 'url' => $this->endpoint .'user', + 'data' => [ + 'name' => 'foo', + 'email' => 'foo@domain.com' + ] + ]); + + $options = $request->getCurlOptions(); + + $this->assertEquals('foo', $options[10015]['name']); + $this->assertEquals('foo@domain.com', $options[10015]['email']); + $this->assertEquals('POST', $options[10036]); + + $request->send(); + + $options = $request->getCurlOptions(); + + $this->assertEquals('foo', $options[10015]['name']); + $this->assertEquals('foo@domain.com', $options[10015]['email']); + $this->assertEquals('POST', $options[10036]); + $this->assertEquals(true, $options[19913]); + $this->assertEquals(true, $options[2]); + } + + /** + * setCurlOption() + */ + public function testOptionsSetter() + { + $request = new \sylouuu\Curl\Get([ + 'url' => $this->endpoint .'user' + ]); + + $options = $request->getCurlOptions(); + + $this->assertEquals(null, $options[27]); + + $request->setCurlOption(CURLOPT_CRLF, true); + + $options = $request->getCurlOptions(); + + $this->assertEquals(true, $options[27]); + } + + /** + * getCurlInfo() + */ + public function testCurlInfoGetter() + { + $request = new \sylouuu\Curl\Get([ + 'url' => $this->endpoint .'user', + 'autoclose' => false + ]); + + $request->send(); + + $code = $request->getCurlInfo(CURLINFO_HTTP_CODE); + + $request->close(); + + $this->assertEquals(200, $code); + } + + } diff --git a/tests/RESTClientTest.php b/tests/RESTClientTest.php deleted file mode 100644 index 17a15c4..0000000 --- a/tests/RESTClientTest.php +++ /dev/null @@ -1,127 +0,0 @@ -rest_client = new \sylouuu\RESTClient(); - - // Setting endpoint URL - $this->endpoint['default'] = 'http://ip.jsontest.com/'; - $this->endpoint['headers'] = 'http://headers.jsontest.com/'; - } - - // Exceptions - // ------------------------------------------------------------------------------------------------------ - - /** - * Standard POST request without data - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No data provided for that POST request - */ - public function testExceptionPostRequestWithoutData() { - $this->rest_client->post([ - 'url' => $this->endpoint['default'] - ]); - } - - /** - * Standard PUT request without data - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No data provided for that PUT request - */ - public function testExceptionPutRequestWithoutData() { - $this->rest_client->put([ - 'url' => $this->endpoint['default'] - ]); - } - - // Success - // ------------------------------------------------------------------------------------------------------ - - /** - * Standard GET request - */ - public function testGetRequest() { - $request = $this->rest_client->get([ - 'url' => $this->endpoint['default'] - ]); - - $this->assertEquals(200, $request->getStatus()); - $this->assertArrayHasKey('ip', json_decode($request->getResponse(), true)); - } - - /** - * Standard GET request with specific header - */ - public function testGetRequestWithHeader() { - $request = $this->rest_client->get([ - 'url' => $this->endpoint['headers'], - 'headers' => [ - 'Authorization: foobar' - ] - ]); - - $this->assertEquals(200, $request->getStatus()); - $this->assertArrayHasKey('Authorization', json_decode($request->getResponse(), true)); - } - - /** - * Standard POST request with data - */ - public function testPostRequest() { - $request = $this->rest_client->post([ - 'url' => $this->endpoint['default'], - 'data' => [ - 'foo' => 'bar' - ] - ]); - - $this->assertEquals(200, $request->getStatus()); - $this->assertArrayHasKey('ip', json_decode($request->getResponse(), true)); - } - - /** - * Standard POST request with data & specific header - */ - public function testPostRequestWithHeader() { - $request = $this->rest_client->post([ - 'url' => $this->endpoint['headers'], - 'headers' => [ - 'Authorization: foobar' - ], - 'data' => [ - 'foo' => 'bar' - ] - ]); - - $this->assertEquals(200, $request->getStatus()); - $this->assertArrayHasKey('Authorization', json_decode($request->getResponse(), true)); - } - - } - -?> \ No newline at end of file