Skip to content

Commit 0ac5857

Browse files
authored
Merge pull request #1119 from gdebrauwer/fix-actingasclient-testing-method
[8.x] Fix 'actingAsClient' testing method
2 parents dce3ba6 + ae79892 commit 0ac5857

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Passport.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,25 @@ public static function actingAs($user, $scopes = [], $guard = 'api')
422422
*/
423423
public static function actingAsClient($client, $scopes = [])
424424
{
425-
$mock = Mockery::mock(ResourceServer::class);
425+
$token = app(self::tokenModel());
426+
$token->client = $client;
427+
$token->scopes = $scopes;
426428

429+
$mock = Mockery::mock(ResourceServer::class);
427430
$mock->shouldReceive('validateAuthenticatedRequest')
428-
->andReturnUsing(function ($request) use ($client, $scopes) {
429-
return $request
430-
->withAttribute('oauth_client_id', $client->id)
431-
->withAttribute('oauth_scopes', $scopes);
431+
->andReturnUsing(function ($request) use ($token) {
432+
return $request->withAttribute('oauth_client_id', $token->client->id)
433+
->withAttribute('oauth_access_token_id', $token->id)
434+
->withAttribute('oauth_scopes', $token->scopes);
432435
});
433436

434437
app()->instance(ResourceServer::class, $mock);
435438

439+
$mock = Mockery::mock(TokenRepository::class);
440+
$mock->shouldReceive('find')->andReturn($token);
441+
442+
app()->instance(TokenRepository::class, $mock);
443+
436444
return $client;
437445
}
438446

0 commit comments

Comments
 (0)