diff --git a/src/Client.php b/src/Client.php index 2c608eeb3a..fae7521cb6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -706,9 +706,10 @@ protected function openTempStream() */ public function setAuth($user, $password, $type = self::AUTH_BASIC) { - if (!defined('self::AUTH_' . strtoupper($type))) { + if (!defined('static::AUTH_' . strtoupper($type))) { throw new Exception\InvalidArgumentException("Invalid or not supported authentication type: '$type'"); } + if (empty($user)) { throw new Exception\InvalidArgumentException("The username cannot be empty"); } @@ -717,7 +718,6 @@ public function setAuth($user, $password, $type = self::AUTH_BASIC) 'user' => $user, 'password' => $password, 'type' => $type - ); return $this; diff --git a/test/ClientTest.php b/test/ClientTest.php index 4433ed7623..da22793267 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -18,6 +18,7 @@ use Zend\Http\Request; use Zend\Http\Response; use Zend\Http\Client\Adapter\Test; +use ZendTest\Http\TestAsset\ExtendedClient; class ClientTest extends \PHPUnit_Framework_TestCase @@ -374,4 +375,24 @@ public function testPrepareHeadersCreateRightHttpField() $this->assertArrayNotHasKey('content-length', $headers); $this->assertArrayHasKey('Content-Length', $headers); } + + /** + * @group 6301 + */ + public function testCanSpecifyCustomAuthMethodsInExtendingClasses() + { + $client = new ExtendedClient(); + + $client->setAuth('username', 'password', ExtendedClient::AUTH_CUSTOM); + + $this->assertAttributeEquals( + array ( + 'user' => 'username', + 'password' => 'password', + 'type' => ExtendedClient::AUTH_CUSTOM, + ), + 'auth', + $client + ); + } } diff --git a/test/TestAsset/ExtendedClient.php b/test/TestAsset/ExtendedClient.php new file mode 100644 index 0000000000..170bef0e6e --- /dev/null +++ b/test/TestAsset/ExtendedClient.php @@ -0,0 +1,10 @@ +