Fixed setting of default headers array
This commit is contained in:
@@ -84,7 +84,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public static function defaultHeaders($headers)
|
public static function defaultHeaders($headers)
|
||||||
{
|
{
|
||||||
return array_merge(self::$defaultHeaders, $headers);
|
return self::$defaultHeaders = array_merge(self::$defaultHeaders, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,6 +39,31 @@ class UnirestRequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
Unirest\Request::timeout(null); // Cleaning timeout for the other tests
|
Unirest\Request::timeout(null); // Cleaning timeout for the other tests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDefaultHeaders()
|
||||||
|
{
|
||||||
|
$defaultHeaders = array(
|
||||||
|
'header1' => 'Hello',
|
||||||
|
'header2' => 'world'
|
||||||
|
);
|
||||||
|
Unirest\Request::defaultHeaders($defaultHeaders);
|
||||||
|
|
||||||
|
$response = Unirest\Request::get('http://mockbin.com/request');
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->code);
|
||||||
|
$this->assertObjectHasAttribute('header1', $response->body->headers);
|
||||||
|
$this->assertEquals('Hello', $response->body->headers->header1);
|
||||||
|
$this->assertObjectHasAttribute('header2', $response->body->headers);
|
||||||
|
$this->assertEquals('world', $response->body->headers->header2);
|
||||||
|
|
||||||
|
Unirest\Request::clearDefaultHeaders();
|
||||||
|
|
||||||
|
$response = Unirest\Request::get('http://mockbin.com/request');
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->code);
|
||||||
|
$this->assertObjectNotHasAttribute('header1', $response->body->headers);
|
||||||
|
$this->assertObjectNotHasAttribute('header2', $response->body->headers);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDefaultHeader()
|
public function testDefaultHeader()
|
||||||
{
|
{
|
||||||
Unirest\Request::defaultHeader('Hello', 'custom');
|
Unirest\Request::defaultHeader('Hello', 'custom');
|
||||||
|
|||||||
Reference in New Issue
Block a user