It sounds like the issue you're experiencing is related to the environment configuration not being properly applied when running Dusk tests. Here are a few steps you can take to ensure that Dusk is using the correct database:
-
Ensure
.env.dusk.localis being used: Make sure that when you run your Dusk tests, the.env.dusk.localfile is being loaded. You can verify this by adding a unique environment variable in.env.dusk.localand checking its value in your test. -
Clear Configuration Cache: Run the following commands to clear any cached configuration that might be causing the issue:
php artisan config:clear php artisan cache:clear -
Check Dusk Environment: Ensure that your Dusk environment is correctly set up. You can do this by adding a check in your test to see which database is being used:
test('check database connection', function () { $database = config('database.connections.sqlite.database'); ray($database); // This should output the path to your dusk.sqlite }); -
Database Truncation: Make sure that the
DatabaseTruncationtrait is correctly truncating the database tables before each test. If it's not working as expected, you might want to manually truncate the tables in abeforeEachhook. -
Verify User Creation: Ensure that the user is being created in the correct database. You can do this by checking the database file directly or by outputting the user count after creation:
test('example', function () { $user = User::factory()->admin()->create(); $userCount = User::count(); ray($userCount); // This should reflect the number of users in your dusk.sqlite }); -
Check Browser Session: Since you mentioned that you see the login screen and "Dusk" as the project name, it indicates that the
.env.dusk.localis being loaded. However, ensure that the session is not persisting across tests by clearing cookies or using a fresh session for each test. -
Use a Different Browser Profile: If you're using a browser profile that might be retaining session data, consider using a fresh profile for Dusk tests. You can configure this in your
DuskTestCase.phpby setting a unique profile path.
By following these steps, you should be able to ensure that Dusk is using the correct database for authentication. If the issue persists, consider checking for any custom configurations or middleware that might be affecting the authentication process.