Skip to content

Commit

Permalink
Merge pull request #1083 from gdebrauwer/testing-acting-as-client
Browse files Browse the repository at this point in the history
[7.x] 'actingAsClient' method for tests
  • Loading branch information
taylorotwell authored Sep 13, 2019
2 parents cc39dc6 + 0ce1d8c commit d47175a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DateInterval;
use DateTimeInterface;
use Illuminate\Support\Facades\Route;
use League\OAuth2\Server\ResourceServer;
use Mockery;

class Passport
Expand Down Expand Up @@ -405,6 +406,29 @@ public static function actingAs($user, $scopes = [], $guard = 'api')
return $user;
}

/**
* Set the current client for the application with the given scopes.
*
* @param  \Laravel\Passport\Client  $client
* @param  array  $scopes
* @return \Laravel\Passport\Client
*/
public static function actingAsClient($client, $scopes = [])
{
$mock = Mockery::mock(ResourceServer::class);

$mock->shouldReceive('validateAuthenticatedRequest')
->andReturnUsing(function ($request) use ($client, $scopes) {
return $request
->withAttribute('oauth_client_id', $client->id)
->withAttribute('oauth_scopes', $scopes);
});

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

return $client;
}

/**
* Set the storage location of the encryption keys.
*
Expand Down

0 comments on commit d47175a

Please sign in to comment.