laravel / passport

Laravel Passport provides OAuth2 server support to Laravel.
https://laravel.com/docs/passport
MIT License
3.3k stars 781 forks source link

for Laravel 9.x set the client on the TokenGuard when mocking the client #1680

Closed systemsolutionweb closed 1 year ago

systemsolutionweb commented 1 year ago

Same as #1519 Stub client on guard when calling Passport::actingAsClient()

I'm trying testing a package laravel 9.x with passport 10.x (it has support for 10.x and 11.x)

This PR changes the Passport::actingAsClient() method. Currently when stubbing the client via Passport, the guard doesn't actually reflect the stub:

>>> $client = Laravel\Passport\Database\Factories\ClientFactory::new()->createOne()
=> Laravel\Passport\Client {#4807}
>>> Laravel\Passport\Passport::actingAsClient($client)
=> Laravel\Passport\Client {#4807}
>>> auth()->guard('api')->client()
=> null

After this PR the following happens:

>>> $client = Laravel\Passport\Database\Factories\ClientFactory::new()->createOne()
=> Laravel\Passport\Client {#4807}
>>> Laravel\Passport\Passport::actingAsClient($client, [], 'api')
=> Laravel\Passport\Client {#4807}
>>> auth()->guard('api')->client()
=> Laravel\Passport\Client {#4807}

I'm fairly sure this won't get merged 😖