formatting
This commit is contained in:
@@ -12,4 +12,3 @@
|
||||
const PATCH = "PATCH";
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
{
|
||||
|
||||
private static $verifyPeer = true;
|
||||
|
||||
private static $socketTimeout = null;
|
||||
private static $defaultHeaders = array();
|
||||
|
||||
@@ -15,7 +14,8 @@
|
||||
* Verify SSL peer
|
||||
* @param bool $enabled enable SSL verification, by default is true
|
||||
*/
|
||||
public static function verifyPeer($enabled) {
|
||||
public static function verifyPeer($enabled)
|
||||
{
|
||||
Unirest::$verifyPeer = $enabled;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
* Set a timeout
|
||||
* @param integer $seconds timeout value in seconds
|
||||
*/
|
||||
public static function timeout($seconds) {
|
||||
public static function timeout($seconds)
|
||||
{
|
||||
Unirest::$socketTimeout = $seconds;
|
||||
}
|
||||
|
||||
@@ -32,14 +33,16 @@
|
||||
* @param string $name header name
|
||||
* @param string $value header value
|
||||
*/
|
||||
public static function defaultHeader($name, $value) {
|
||||
public static function defaultHeader($name, $value)
|
||||
{
|
||||
Unirest::$defaultHeaders[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all the default headers
|
||||
*/
|
||||
public static function clearDefaultHeaders() {
|
||||
public static function clearDefaultHeaders()
|
||||
{
|
||||
Unirest::$defaultHeaders = array();
|
||||
}
|
||||
|
||||
@@ -117,7 +120,8 @@
|
||||
* Prepares a file for upload. To be used inside the parameters declaration for a request.
|
||||
* @param string $path The file path
|
||||
*/
|
||||
public static function file($path) {
|
||||
public static function file($path)
|
||||
{
|
||||
if (function_exists("curl_file_create")) {
|
||||
return curl_file_create($path);
|
||||
} else {
|
||||
@@ -129,7 +133,8 @@
|
||||
* This function is useful for serializing multidimensional arrays, and avoid getting
|
||||
* the "Array to string conversion" notice
|
||||
*/
|
||||
private static function http_build_query_for_curl( $arrays, &$new = array(), $prefix = null ) {
|
||||
private static function http_build_query_for_curl($arrays, &$new = array(), $prefix = null)
|
||||
{
|
||||
if (is_object($arrays)) {
|
||||
$arrays = get_object_vars($arrays);
|
||||
}
|
||||
@@ -157,7 +162,8 @@
|
||||
*/
|
||||
private static function request($httpMethod, $url, $body = NULL, $headers = array(), $username = NULL, $password = NULL)
|
||||
{
|
||||
if ($headers == NULL) $headers = array();
|
||||
if ($headers == NULL)
|
||||
$headers = array();
|
||||
$lowercaseHeaders = array();
|
||||
foreach ($headers as $key => $val) {
|
||||
$lowercaseHeaders[] = Unirest::getHeader($key, $val);
|
||||
@@ -219,7 +225,8 @@
|
||||
return new HttpResponse($httpCode, $body, $header);
|
||||
}
|
||||
|
||||
private static function getArrayFromQuerystring($querystring) {
|
||||
private static function getArrayFromQuerystring($querystring)
|
||||
{
|
||||
$pairs = explode("&", $querystring);
|
||||
$vars = array();
|
||||
foreach ($pairs as $pair) {
|
||||
@@ -257,9 +264,11 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function getHeader($key, $val) {
|
||||
private static function getHeader($key, $val)
|
||||
{
|
||||
$key = trim(strtolower($key));
|
||||
if ($key == "user-agent" || $key == "expect") continue;
|
||||
if ($key == "user-agent" || $key == "expect")
|
||||
continue;
|
||||
return $key . ": " . $val;
|
||||
}
|
||||
|
||||
@@ -277,8 +286,7 @@
|
||||
$len = strlen($chunk);
|
||||
$dechunk = null;
|
||||
|
||||
while (($pos < $len)
|
||||
&& ($chunkLenHex = substr($chunk, $pos, ($newlineAt = strpos($chunk, "\n", $pos + 1)) - $pos))) {
|
||||
while (($pos < $len) && ($chunkLenHex = substr($chunk, $pos, ($newlineAt = strpos($chunk, "\n", $pos + 1)) - $pos))) {
|
||||
|
||||
if (!is_hex($chunkLenHex)) {
|
||||
trigger_error('Value is not properly chunk encoded', E_USER_WARNING);
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
<?php
|
||||
|
||||
echo "Running the Unirest-PHP bindings test suite.\n".
|
||||
"If you're trying to use the Unirest-PHP bindings you'll probably want ".
|
||||
"to require('lib/Unirest.php'); instead of this file\n";
|
||||
echo "Running the Unirest-PHP bindings test suite.\n" . "If you're trying to use the Unirest-PHP bindings you'll probably want " . "to require('lib/Unirest.php'); instead of this file\n";
|
||||
|
||||
$ok = @include_once(dirname(__FILE__) . '/simpletest/autorun.php');
|
||||
if (!$ok) {
|
||||
$ok = @include_once(dirname(__FILE__) . '/../vendor/vierbergenlars/simpletest/autorun.php');
|
||||
}
|
||||
if (!$ok) {
|
||||
echo "MISSING DEPENDENCY: The Unirest-PHP test cases depend on SimpleTest. ".
|
||||
"Download it at <http://www.simpletest.org/>, and either install it ".
|
||||
"in your PHP include_path or put it in the test/ directory.\n";
|
||||
echo "MISSING DEPENDENCY: The Unirest-PHP test cases depend on SimpleTest. " . "Download it at <http://www.simpletest.org/>, and either install it " . "in your PHP include_path or put it in the test/ directory.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Throw an exception on any error
|
||||
function exception_error_handler($errno, $errstr, $errfile, $errline) {
|
||||
function exception_error_handler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ class UnirestTest extends UnitTestCase
|
||||
{
|
||||
public function testGet()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get?name=Mark", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::get("http://httpbin.org/get?name=Mark", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
|
||||
@@ -18,8 +19,15 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testGetMultidimensionalArray()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array( "Accept" => "application/json" ),
|
||||
array('key'=>'value','items'=>array('item1','item2')));
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
'key' => 'value',
|
||||
'items' => array(
|
||||
'item1',
|
||||
'item2'
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
@@ -32,8 +40,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testGetWithDots()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"user.name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
@@ -47,8 +56,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testGetWithDots2()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"user.name" => "Mark Bond",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
@@ -62,8 +72,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
@@ -77,8 +88,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testPostWithDots()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"user.name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
@@ -92,8 +104,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testRawPost()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||
json_encode(array(
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
), json_encode(array(
|
||||
"author" => "Sam Sullivan"
|
||||
)));
|
||||
|
||||
@@ -103,16 +116,17 @@ class UnirestTest extends UnitTestCase
|
||||
$this->assertEqual("Sam Sullivan", $json->author);
|
||||
}
|
||||
|
||||
public function testUpload() {
|
||||
public function testUpload()
|
||||
{
|
||||
|
||||
var_dump(file_get_contents(dirname(__FILE__) . "/test_upload.txt"));
|
||||
|
||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"file" => Unirest::file(dirname(__FILE__) . "/test_upload.txt")
|
||||
)
|
||||
);
|
||||
));
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
$files = $response->body->files;
|
||||
@@ -126,8 +140,15 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testPostMultidimensionalArray()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||
array('key'=>'value','items'=>array('item1','item2')));
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
'key' => 'value',
|
||||
'items' => array(
|
||||
'item1',
|
||||
'item2'
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
@@ -139,8 +160,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testPut()
|
||||
{
|
||||
$response = Unirest::put("http://httpbin.org/put", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::put("http://httpbin.org/put", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
@@ -154,8 +176,9 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testPatch()
|
||||
{
|
||||
$response = Unirest::patch("http://httpbin.org/patch", array( "Accept" => "application/json" ),
|
||||
array(
|
||||
$response = Unirest::patch("http://httpbin.org/patch", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
@@ -169,8 +192,10 @@ class UnirestTest extends UnitTestCase
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$response = Unirest::delete("http://httpbin.org/delete", array( "Accept" => "application/json", "Content-Type" => "application/x-www-form-urlencoded" ),
|
||||
array(
|
||||
$response = Unirest::delete("http://httpbin.org/delete", array(
|
||||
"Accept" => "application/json",
|
||||
"Content-Type" => "application/x-www-form-urlencoded"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user