7 Commits
1.2 ... 1.2.1

Author SHA1 Message Date
Marco Palladino
ff13801b7b Merge pull request #41 from scottmotte/master
It needs to go to root namespace
2014-04-05 16:28:21 -07:00
scottmotte
3951a37c2a It needs to go to root namespace 2014-04-04 12:24:36 -07:00
Marco Palladino
9ee16508d2 Merge pull request #39 from scottmotte/master
Fixes file attachments/uploads
2014-03-27 11:41:22 -07:00
scottmotte
0fe3d04e21 Fixes failing spec around CurlFile in 5.5 php and also adds additional spec 2014-03-27 10:47:09 -07:00
scottmotte
1f22deee76 Merge remote-tracking branch 'upstream/master' 2014-03-26 22:31:03 -07:00
thefosk
099fbca53b test 2014-03-19 12:25:27 -07:00
scottmotte
a332765a9b Minor spelling fix 2014-01-07 14:32:51 -08:00
2 changed files with 45 additions and 6 deletions

View File

@@ -133,7 +133,7 @@ class Unirest
* 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)
public static function http_build_query_for_curl($arrays, &$new = array(), $prefix = null)
{
if (is_object($arrays)) {
$arrays = get_object_vars($arrays);
@@ -141,7 +141,7 @@ class Unirest
foreach ($arrays AS $key => $value) {
$k = isset($prefix) ? $prefix . '[' . $key . ']' : $key;
if (is_array($value) OR is_object($value)) {
if (!$value instanceof \CURLFile AND (is_array($value) OR is_object($value))) {
Unirest::http_build_query_for_curl($value, $new, $k);
} else {
$new[$k] = $value;

View File

@@ -113,6 +113,17 @@ class UnirestTest extends UnitTestCase
$args = $response->body->args;
$this->assertEqual("Mark=Hello", $args->name);
$response = Unirest::get("http://httpbin.org/get", array(
"Accept" => "application/json"
), array(
"name" => "Mark=Hello=John"
));
$this->assertEqual(200, $response->code);
$args = $response->body->args;
$this->assertEqual("Mark=Hello=John", $args->name);
}
public function testPostArray()
@@ -193,6 +204,23 @@ class UnirestTest extends UnitTestCase
$this->assertEqual("Mark", $form->name);
}
public function testUploadIfFilePartOfData()
{
$response = Unirest::post("http://httpbin.org/post", array(
"Accept" => "application/json"
), array(
"name" => "Mark",
"files[owl.gif]" => Unirest::file(dirname(__FILE__) . "/test_upload.txt")
));
$this->assertEqual(200, $response->code);
//$files = $response->body->files;
//$this->assertEqual("This is a test", $files->file);
$form = $response->body->form;
$this->assertEqual("Mark", $form->name);
}
public function testPostMultidimensionalArray()
{
$response = Unirest::post("http://httpbin.org/post", array(
@@ -332,4 +360,15 @@ class UnirestTest extends UnitTestCase
$this->assertEqual("ciao", $headers->{'User-Agent'});
}
public function testHttpBuildQueryWhenCurlFile()
{
$file = Unirest::file(dirname(__FILE__) . "/test_upload.txt");
$body = array(
"to" => "mail@mailinator.com",
"from" => "mail@mailinator.com",
"file" => $file
);
Unirest::http_build_query_for_curl($body, $postBody);
$this->assertEqual($postBody['file'], $file);
}
}