Skip to content

Commit 49272f3

Browse files
Changed authhandler to use array (#361)
1 parent 02ae3fc commit 49272f3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Client/APIResource.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class APIResource implements ClientAwareInterface
3333
use ClientAwareTrait;
3434
use LoggerTrait;
3535

36-
protected ?HandlerInterface $authHandler = null;
36+
/**
37+
* @var HandlerInterface[]
38+
*/
39+
protected array $authHandler = [];
3740

3841
/**
3942
* Base URL that we will hit. This can be overridden from the underlying
@@ -349,6 +352,9 @@ public function search(?FilterInterface $filter = null, string $uri = ''): Itera
349352
*/
350353
public function setAuthHandler($handler): self
351354
{
355+
if (!is_array($handler)) {
356+
$handler = [$handler];
357+
}
352358
$this->authHandler = $handler;
353359

354360
return $this;

test/Client/APIResourceTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use VonageTest\VonageTestCase;
1515
use Vonage\Client;
1616
use Vonage\Client\APIResource;
17+
use Vonage\Client\Credentials\Handler\BasicHandler;
18+
use Vonage\Client\Credentials\Handler\SignatureBodyHandler;
1719

1820
class APIResourceTest extends VonageTestCase
1921
{
@@ -42,4 +44,20 @@ public function testNotOverridingBaseURLReturnsBlank(): void
4244
$resource = new APIResource();
4345
$this->assertSame('', $resource->getBaseUrl());
4446
}
47+
48+
public function testCanSetMultipleAuthHandlers(): void
49+
{
50+
$resource = new APIResource();
51+
$resource->setAuthHandler([new BasicHandler(), new SignatureBodyHandler()]);
52+
53+
$this->assertIsArray($resource->getAuthHandler());
54+
}
55+
56+
public function testSingleAuthHanlderConvertedToArray(): void
57+
{
58+
$resource = new APIResource();
59+
$resource->setAuthHandler(new BasicHandler());
60+
61+
$this->assertIsArray($resource->getAuthHandler());
62+
}
4563
}

0 commit comments

Comments
 (0)