Skip to content

Commit dcce996

Browse files
authored
Fix IterableAPICollection Auth Handling (#379)
* Mark potentially major bug * Fix to pull in the auth handling to the IterableApiCollection
1 parent ccbbf9c commit dcce996

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/Client.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ class Client implements LoggerAwareInterface
141141
/**
142142
* Create a new API client using the provided credentials.
143143
*/
144-
public function __construct(CredentialsInterface $credentials, $options = [], ?ClientInterface $client = null)
145-
{
144+
public function __construct(
145+
CredentialsInterface $credentials,
146+
$options = [],
147+
?ClientInterface $client = null
148+
) {
146149
if (is_null($client)) {
147150
// Since the user did not pass a client, try and make a client
148151
// using the Guzzle 6 adapter or Guzzle 7 (depending on availability)

src/Entity/IterableAPICollection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ protected function fetchPage($absoluteUri): void
474474
}
475475

476476
$request = new Request($requestUri, 'GET');
477+
478+
if ($this->getApiResource()->getAuthHandler()) {
479+
$this->getApiResource()->addAuth($request);
480+
}
481+
477482
$response = $this->client->send($request);
478483

479484
$this->getApiResource()->setLastRequest($request);

test/Insights/ClientTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function setUp(): void
4949
{
5050
$this->vonageClient = $this->prophesize(Client::class);
5151
$this->vonageClient->getApiUrl()->willReturn('http://api.nexmo.com');
52+
$this->vonageClient->getCredentials()->willReturn(
53+
new Client\Credentials\Container(
54+
new Client\Credentials\Basic('abc', 'def'),
55+
)
56+
);
5257

5358
$this->api = new APIResource();
5459
$this->api->setIsHAL(false);

test/Messages/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ public function testCanSendViberText(): void
645645
public function testThrowsRequestErrorOnBadRequest(): void
646646
{
647647
$this->expectException(Client\Exception\Request::class);
648-
$this->expectErrorMessage('The request body did not contain valid JSON: Unexpected character (\'"\' (code 34)): was expecting comma to separate Object entries');
648+
$this->expectExceptionMessage('The request body did not contain valid JSON: Unexpected character (\'"\' (code 34)): was expecting comma to separate Object entries');
649649

650650
$payload = [
651651
'to' => '447700900000',
@@ -671,7 +671,7 @@ public function testThrowsRequestErrorOnBadRequest(): void
671671
public function testThrowsRateLimit(): void
672672
{
673673
$this->expectException(Client\Exception\ThrottleException::class);
674-
$this->expectErrorMessage('Rate Limit Hit: Please wait, then retry your request');
674+
$this->expectExceptionMessage('Rate Limit Hit: Please wait, then retry your request');
675675

676676
$payload = [
677677
'to' => '447700900000',

0 commit comments

Comments
 (0)