massive cleanups
- renamed classes - updated to phpunit - more PSR compliance
This commit is contained in:
1
test/.gitignore
vendored
1
test/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
simpletest
|
||||
@@ -1,27 +0,0 @@
|
||||
<?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";
|
||||
|
||||
$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";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Throw an exception on any error
|
||||
function exception_error_handler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
|
||||
}
|
||||
|
||||
set_error_handler('exception_error_handler');
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
require_once(dirname(__FILE__) . '/../lib/Unirest.php');
|
||||
|
||||
require_once(dirname(__FILE__) . '/Unirest/UnirestTest.php');
|
||||
|
||||
?>
|
||||
@@ -1,27 +1,33 @@
|
||||
<?php
|
||||
|
||||
class UnirestTest extends UnitTestCase
|
||||
use Unirest\Request as Request;
|
||||
|
||||
namespace Unirest;
|
||||
|
||||
define('UPLOAD_FIXTURE', dirname(dirname(__FILE__)) . '/fixtures/upload.txt');
|
||||
|
||||
class UnirestTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get?name=Mark", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::get('http://httpbin.org/get?name=Mark', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"nick" => "thefosk"
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
$this->assertEqual("Mark", $args->name);
|
||||
$this->assertEqual("thefosk", $args->nick);
|
||||
$this->assertEquals('Mark', $args->name);
|
||||
$this->assertEquals('thefosk', $args->nick);
|
||||
}
|
||||
|
||||
|
||||
public function testGetMultidimensionalArray()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::get('http://httpbin.org/get', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
'key' => 'value',
|
||||
'items' => array(
|
||||
@@ -29,202 +35,204 @@ class UnirestTest extends UnitTestCase
|
||||
'item2'
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
|
||||
$this->assertEqual("value", $args->key);
|
||||
$this->assertEqual("item1", $args->{"items[0]"});
|
||||
$this->assertEqual("item2", $args->{"items[1]"});
|
||||
|
||||
$this->assertEquals('value', $args->key);
|
||||
$this->assertEquals('item1', $args->{'items[0]'});
|
||||
$this->assertEquals('item2', $args->{'items[1]'});
|
||||
}
|
||||
|
||||
|
||||
public function testGetWithDots()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::get('http://httpbin.org/get', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"user.name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
'user.name' => 'Mark',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
$this->assertEqual("Mark", $args->{"user.name"});
|
||||
$this->assertEqual("thefosk", $args->nick);
|
||||
$this->assertEquals('Mark', $args->{'user.name'});
|
||||
$this->assertEquals('thefosk', $args->nick);
|
||||
}
|
||||
|
||||
|
||||
public function testGetWithDots2()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::get('http://httpbin.org/get', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"user.name" => "Mark Bond",
|
||||
"nick" => "thefosk"
|
||||
'user.name' => 'Mark Bond',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
$this->assertEqual("Mark Bond", $args->{"user.name"});
|
||||
$this->assertEqual("thefosk", $args->nick);
|
||||
$this->assertEquals('Mark Bond', $args->{'user.name'});
|
||||
$this->assertEquals('thefosk', $args->nick);
|
||||
}
|
||||
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
'name' => 'Mark',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark", $form->name);
|
||||
$this->assertEqual("thefosk", $form->nick);
|
||||
$this->assertEquals('Mark', $form->name);
|
||||
$this->assertEquals('thefosk', $form->nick);
|
||||
}
|
||||
|
||||
public function testPostWithEqualSign()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"name" => "Mark=Hello"
|
||||
'name' => 'Mark=Hello'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark=Hello", $form->name);
|
||||
$this->assertEquals('Mark=Hello', $form->name);
|
||||
}
|
||||
|
||||
public function testGetWithEqualSign()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::get('http://httpbin.org/get', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"name" => "Mark=Hello"
|
||||
'name' => 'Mark=Hello'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
$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);
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
$this->assertEqual("Mark=Hello=John", $args->name);
|
||||
$this->assertEquals('Mark=Hello', $args->name);
|
||||
|
||||
$response = Request::get('http://httpbin.org/get', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
'name' => 'Mark=Hello=John'
|
||||
));
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
$this->assertEquals('Mark=Hello=John', $args->name);
|
||||
}
|
||||
|
||||
public function testPostArray()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"name[0]" => "Mark",
|
||||
"name[1]" => "John"
|
||||
'name[0]' => 'Mark',
|
||||
'name[1]' => 'John'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
|
||||
$this->assertEqual("Mark", $form->{"name[0]"});
|
||||
$this->assertEqual("John", $form->{"name[1]"});
|
||||
$this->assertEquals('Mark', $form->{'name[0]'});
|
||||
$this->assertEquals('John', $form->{'name[1]'});
|
||||
}
|
||||
|
||||
public function testGetArray()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", array(), array(
|
||||
"name[0]" => "Mark",
|
||||
"name[1]" => "John"
|
||||
$response = Request::get('http://httpbin.org/get', array(), array(
|
||||
'name[0]' => 'Mark',
|
||||
'name[1]' => 'John'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$args = $response->body->args;
|
||||
$this->assertEqual("Mark", $args->{"name[0]"});
|
||||
$this->assertEqual("John", $args->{"name[1]"});
|
||||
$this->assertEquals('Mark', $args->{'name[0]'});
|
||||
$this->assertEquals('John', $args->{'name[1]'});
|
||||
}
|
||||
|
||||
|
||||
public function testPostWithDots()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"user.name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
'user.name' => 'Mark',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark", $form->{"user.name"});
|
||||
$this->assertEqual("thefosk", $form->nick);
|
||||
$this->assertEquals('Mark', $form->{'user.name'});
|
||||
$this->assertEquals('thefosk', $form->nick);
|
||||
}
|
||||
|
||||
|
||||
public function testRawPost()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json'
|
||||
), json_encode(array(
|
||||
"author" => "Sam Sullivan"
|
||||
'author' => 'Sam Sullivan'
|
||||
)));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$json = $response->body->json;
|
||||
$this->assertEqual("Sam Sullivan", $json->author);
|
||||
|
||||
$this->assertEquals('Sam Sullivan', $json->author);
|
||||
}
|
||||
|
||||
|
||||
public function testUpload()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
{
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"file" => Unirest::file(dirname(__FILE__) . "/test_upload.txt")
|
||||
'name' => 'Mark',
|
||||
'file' => Request::file(UPLOAD_FIXTURE)
|
||||
));
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$files = $response->body->files;
|
||||
$this->assertEqual("This is a test", $files->file);
|
||||
|
||||
$this->assertEquals('This is a test', $files->file);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark", $form->name);
|
||||
$this->assertEquals('Mark', $form->name);
|
||||
}
|
||||
|
||||
public function testUploadIfFilePartOfData()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
{
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"files[owl.gif]" => Unirest::file(dirname(__FILE__) . "/test_upload.txt")
|
||||
'name' => 'Mark',
|
||||
'files[owl.gif]' => Request::file(UPLOAD_FIXTURE)
|
||||
));
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
//$files = $response->body->files;
|
||||
//$this->assertEqual("This is a test", $files->file);
|
||||
|
||||
//$this->assertEquals('This is a test', $files->file);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark", $form->name);
|
||||
$this->assertEquals('Mark', $form->name);
|
||||
}
|
||||
|
||||
|
||||
public function testPostMultidimensionalArray()
|
||||
{
|
||||
$response = Unirest::post("http://httpbin.org/post", array(
|
||||
"Accept" => "application/json"
|
||||
$response = Request::post('http://httpbin.org/post', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
'key' => 'value',
|
||||
'items' => array(
|
||||
@@ -232,143 +240,145 @@ class UnirestTest extends UnitTestCase
|
||||
'item2'
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("value", $form->key);
|
||||
$this->assertEqual("item1", $form->{"items[0]"});
|
||||
$this->assertEqual("item2", $form->{"items[1]"});
|
||||
}
|
||||
|
||||
public function testPut()
|
||||
{
|
||||
$response = Unirest::put("http://httpbin.org/put", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark", $form->name);
|
||||
$this->assertEqual("thefosk", $form->nick);
|
||||
}
|
||||
|
||||
public function testPatch()
|
||||
{
|
||||
$response = Unirest::patch("http://httpbin.org/patch", array(
|
||||
"Accept" => "application/json"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEqual("Mark", $form->name);
|
||||
$this->assertEqual("thefosk", $form->nick);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$response = Unirest::delete("http://httpbin.org/delete", array(
|
||||
"Accept" => "application/json",
|
||||
"Content-Type" => "application/x-www-form-urlencoded"
|
||||
), array(
|
||||
"name" => "Mark",
|
||||
"nick" => "thefosk"
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
$data = $response->body->data;
|
||||
$this->assertFalse(empty($data));
|
||||
}
|
||||
|
||||
public function testTimeoutFail()
|
||||
{
|
||||
Unirest::timeout(1);
|
||||
|
||||
$this->expectException();
|
||||
$response = Unirest::get("http://httpbin.org/delay/3");
|
||||
|
||||
Unirest::timeout(null); // Cleaning timeout for the other tests
|
||||
}
|
||||
|
||||
public function testTimeoutSuccess()
|
||||
{
|
||||
Unirest::timeout(3);
|
||||
|
||||
$response = Unirest::get("http://httpbin.org/delay/1");
|
||||
$this->assertEqual(200, $response->code);
|
||||
|
||||
Unirest::timeout(null); // Cleaning timeout for the other tests
|
||||
}
|
||||
|
||||
public function testDefaultHeader()
|
||||
{
|
||||
Unirest::defaultHeader("Hello", "custom");
|
||||
$response = Unirest::get("http://httpbin.org/get");
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
$headers = $response->body->headers;
|
||||
$properties = get_object_vars($headers);
|
||||
$this->assertTrue(array_key_exists("Hello", $properties));
|
||||
$this->assertEqual("custom", $headers->Hello);
|
||||
$response = Unirest::get("http://httpbin.org/get");
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
$headers = $response->body->headers;
|
||||
$properties = get_object_vars($headers);
|
||||
$this->assertTrue(array_key_exists("Hello", $properties));
|
||||
$this->assertEqual("custom", $headers->Hello);
|
||||
Unirest::clearDefaultHeaders();
|
||||
$response = Unirest::get("http://httpbin.org/get");
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
$headers = $response->body->headers;
|
||||
$properties = get_object_vars($headers);
|
||||
$this->assertFalse(array_key_exists("Hello", $properties));
|
||||
}
|
||||
|
||||
public function testGzip()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/gzip");
|
||||
$args = $response->body;
|
||||
$this->assertEqual(true, $args->gzipped);
|
||||
}
|
||||
|
||||
public function testBasicAuthentication()
|
||||
{
|
||||
$response = Unirest::get("http://httpbin.org/get", null, null, "user", "password");
|
||||
$headers = $response->body->headers;
|
||||
$this->assertEqual("Basic dXNlcjpwYXNzd29yZA==", $headers->Authorization);
|
||||
$this->assertEquals('value', $form->key);
|
||||
$this->assertEquals('item1', $form->{'items[0]'});
|
||||
$this->assertEquals('item2', $form->{'items[1]'});
|
||||
}
|
||||
|
||||
public function testCustomHeaders()
|
||||
public function testPut()
|
||||
{
|
||||
$response = Unirest::get('http://httpbin.org/get', array(
|
||||
$response = Request::put('http://httpbin.org/put', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
'name' => 'Mark',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEquals('Mark', $form->name);
|
||||
$this->assertEquals('thefosk', $form->nick);
|
||||
}
|
||||
|
||||
public function testPatch()
|
||||
{
|
||||
$response = Request::patch('http://httpbin.org/patch', array(
|
||||
'Accept' => 'application/json'
|
||||
), array(
|
||||
'name' => 'Mark',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$form = $response->body->form;
|
||||
$this->assertEquals('Mark', $form->name);
|
||||
$this->assertEquals('thefosk', $form->nick);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$response = Request::delete('http://httpbin.org/delete', array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded'
|
||||
), array(
|
||||
'name' => 'Mark',
|
||||
'nick' => 'thefosk'
|
||||
));
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
$data = $response->body->data;
|
||||
$this->assertTrue(empty($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testTimeoutFail()
|
||||
{
|
||||
Request::timeout(1);
|
||||
|
||||
$response = Request::get('http://httpbin.org/delay/3');
|
||||
|
||||
Request::timeout(null); // Cleaning timeout for the other tests
|
||||
}
|
||||
|
||||
public function testTimeoutSuccess()
|
||||
{
|
||||
Request::timeout(3);
|
||||
|
||||
$response = Request::get('http://httpbin.org/delay/1');
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
Request::timeout(null); // Cleaning timeout for the other tests
|
||||
}
|
||||
|
||||
public function testDefaultHeader()
|
||||
{
|
||||
Request::defaultHeader('Hello', 'custom');
|
||||
$response = Request::get('http://httpbin.org/get');
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
$headers = $response->body->headers;
|
||||
$properties = get_object_vars($headers);
|
||||
$this->assertTrue(array_key_exists('Hello', $properties));
|
||||
$this->assertEquals('custom', $headers->Hello);
|
||||
$response = Request::get('http://httpbin.org/get');
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
$headers = $response->body->headers;
|
||||
$properties = get_object_vars($headers);
|
||||
$this->assertTrue(array_key_exists('Hello', $properties));
|
||||
$this->assertEquals('custom', $headers->Hello);
|
||||
Request::clearDefaultHeaders();
|
||||
$response = Request::get('http://httpbin.org/get');
|
||||
|
||||
$this->assertEquals(200, $response->code);
|
||||
$headers = $response->body->headers;
|
||||
$properties = get_object_vars($headers);
|
||||
$this->assertFalse(array_key_exists('Hello', $properties));
|
||||
}
|
||||
|
||||
public function testGzip()
|
||||
{
|
||||
$response = Request::get('http://httpbin.org/gzip');
|
||||
$args = $response->body;
|
||||
$this->assertEquals(true, $args->gzipped);
|
||||
}
|
||||
|
||||
public function testBasicAuthentication()
|
||||
{
|
||||
$response = Request::get('http://httpbin.org/get', null, null, 'user', 'password');
|
||||
$headers = $response->body->headers;
|
||||
$this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $headers->Authorization);
|
||||
}
|
||||
|
||||
public function testCustomHeaders()
|
||||
{
|
||||
$response = Request::get('http://httpbin.org/get', array(
|
||||
'user-agent' => 'ciao',
|
||||
));
|
||||
|
||||
$this->assertEqual(200, $response->code);
|
||||
$this->assertEquals(200, $response->code);
|
||||
|
||||
$headers = $response->body->headers;
|
||||
$this->assertEqual("ciao", $headers->{'User-Agent'});
|
||||
$this->assertEquals('ciao', $headers->{'User-Agent'});
|
||||
}
|
||||
|
||||
public function testHttpBuildQueryWhenCurlFile()
|
||||
{
|
||||
$file = Unirest::file(dirname(__FILE__) . "/test_upload.txt");
|
||||
$file = Request::file(UPLOAD_FIXTURE);
|
||||
$body = array(
|
||||
"to" => "mail@mailinator.com",
|
||||
"from" => "mail@mailinator.com",
|
||||
"file" => $file
|
||||
'to' => 'mail@mailinator.com',
|
||||
'from' => 'mail@mailinator.com',
|
||||
'file' => $file
|
||||
);
|
||||
Unirest::http_build_query_for_curl($body, $postBody);
|
||||
$this->assertEqual($postBody['file'], $file);
|
||||
Request::buildHTTPCurlQuery($body, $postBody);
|
||||
$this->assertEquals($postBody['file'], $file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user