Skip to content

Commit 5464b9a

Browse files
committed
Updated tests to model failed access token scenario
1 parent 58c864e commit 5464b9a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/OAuth2MiddlewareTest.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ public function testOnErrorDoesTriggerForOAuthRequests()
244244

245245
// Setup Reauthorization Client
246246
$reauth_responder = new MockHandler([
247+
// This token is returned and used for the first request
248+
new Psr7Response(200, [], json_encode([
249+
'access_token' => $mock_access_token,
250+
])),
251+
// The endpoint returned 401, so the previous token was deleted and this one is fetched:
247252
new Psr7Response(200, [], json_encode([
248253
'access_token' => $mock_access_token,
249254
])),
@@ -295,7 +300,7 @@ public function testOnErrorDoesTriggerForOAuthRequests()
295300

296301
$response = $client->get('/');
297302

298-
$this->assertCount(1, $reauth_container);
303+
$this->assertCount(2, $reauth_container);
299304
$this->assertCount(2, $container);
300305

301306
// This proves that the access_token received from the reauth_client was used to authenticate this response
@@ -548,7 +553,7 @@ public function testOnErrorDoesNotLoop()
548553
// We let the ServerException (the Error 500) bubble up to PHPUnit
549554
}
550555

551-
$this->assertCount(1, $reauth_container);
556+
$this->assertCount(2, $reauth_container);
552557
$this->assertCount(2, $container);
553558

554559
// This proves that the access_token received from the reauth_client was used to authenticate this response

0 commit comments

Comments
 (0)