From d5a7ad40bdf925d96732fd65298697e7207288ad Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Thu, 5 Feb 2015 13:00:49 -0500 Subject: [PATCH] fix to deprecated method + more tests --- src/Unirest/Request.php | 2 +- tests/Unirest/RequestTest.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Unirest/Request.php b/src/Unirest/Request.php index 262cfe1..dca202b 100644 --- a/src/Unirest/Request.php +++ b/src/Unirest/Request.php @@ -345,7 +345,7 @@ class Request // supporting deprecated http auth method if (!empty($username)) { curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, self::$auth['user'] . ':' . self::$auth['pass']); + curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); } if (!empty(self::$auth['user'])) { diff --git a/tests/Unirest/RequestTest.php b/tests/Unirest/RequestTest.php index e51f773..44d1024 100644 --- a/tests/Unirest/RequestTest.php +++ b/tests/Unirest/RequestTest.php @@ -71,13 +71,21 @@ class UnirestRequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals(true, $args->gzipped); } - public function testBasicAuthentication() + public function testBasicAuthenticationDeprecated() { $response = Unirest\Request::get('http://httpbin.org/get', array(), array(), 'user', 'password'); $headers = $response->body->headers; $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $headers->Authorization); } + public function testBasicAuthentication() + { + Unirest\Request::auth('user', 'password'); + $response = Unirest\Request::get('http://httpbin.org/get'); + + $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $response->body->headers->Authorization); + } + public function testCustomHeaders() { $response = Unirest\Request::get('http://httpbin.org/get', array(