@automica Why are you manually creating tokens? Passport is meant for adding an OAuth server to your application, so you should be using one of the standard OAuth flows to authenticate users.
Mocking passport for feature test
Hi all, I'm working on a feature for an api where a user can login directly after registration.
I'm doing this by generating a token using passport:
$token = $user->createToken('token')->accessToken; and then passing it back in the response.
Whilst I've tested this against the dev db using postman (and get a token back correctly), I'm having some issues with this as part of a feature test and get the following error:
RuntimeException: Personal access client not found. Please create one. in /var/www/html/vendor/laravel/passport/src/ClientRepository.php:122
This suggests I need to install passport and I have attempted this as such:
php artisan passport:install --force --env=testing
but the command signature doesn't accept the --env flag to target the testing db.
I've tried partial mocking the createToken method on User but it doesnt look like its being called as I would expect so I'm at a bit of a loss.
Any work arounds / help with mocking would be appreciated.
the solution I've found is to add
$this->artisan('passport:install');
to setUp() in TestCase.php
Please or to participate in this conversation.