Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/zendframework/zendframework#6301-http-auth-uses…
Browse files Browse the repository at this point in the history
…-static-for-constants' into develop

Close zendframework/zendframework#6301
  • Loading branch information
Ocramius committed Jul 28, 2014
3 parents b286e16 + 9b36b3b + 53a80f2 commit 15a94d6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -717,7 +718,6 @@ public function setAuth($user, $password, $type = self::AUTH_BASIC)
'user' => $user,
'password' => $password,
'type' => $type

);

return $this;
Expand Down
21 changes: 21 additions & 0 deletions test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}
}
10 changes: 10 additions & 0 deletions test/TestAsset/ExtendedClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace ZendTest\Http\TestAsset;

use Zend\Http\Client;

class ExtendedClient extends Client
{
const AUTH_CUSTOM = 'custom';
}

0 comments on commit 15a94d6

Please sign in to comment.