Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bensigmon's avatar

RefreshDatabase trait breaks feature tests for Passport api

I have several features in an api I'm creating, using Passport for token authentication. I am looking to streamline my tests, and the first part of the Laravel documentation says to use the RefreshDatabase trait to reset the database for each test.

https://laravel.com/docs/8.x/database-testing#resetting-the-database-after-each-test

However, when I add this trait, tests fail with the message RuntimeException Personal access client not found. Please create one.

It looks like this trait is wiping out my Passport personal client. Is there a way to fix this?

0 likes
3 replies
Nakov's avatar

And that's the proper way you should do your tests, each test should start with a clean state and not depend on each other. For initializing a state before each test you can use PHPUnit's setUp() function, which will initialize whatever is needed before each test. And you should be using a factory which creates the tokens.

You could also run seeders before each test, which will seed your database with whatever is expected: https://laravel.com/docs/8.x/database-testing#running-seeders

bensigmon's avatar

So how do I run the php artisan passport:install command in the setup() function?

Please or to participate in this conversation.