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

kenprogrammer's avatar

API Testing Override Sanctum default factory behaviour

According to the docs, when testing Sanctum APIs you use the following code to create and login user:

Sanctum::actingAs(
        User::factory()->create(),
        ['view-tasks']
    );

In my case am using a different user table from a different Desktop system and I've implemented an API using Sanctum to post data into the system. How can override this to ensure user is created and logged in during test runs?

0 likes
0 replies

Please or to participate in this conversation.