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

cerberuspup's avatar

Getting 401 when testing

I've created a unit test for posting to an api and I'm getting this error

Failed asserting that 401 matches expected 200

Here is my code

$response = $this->json('post', '/api/admin/products/create', [
    'name' => 'Product 1'
]);

$this->assertEquals(200, $response->getStatusCode());

I think what is happening is that I need to be "logged in" to post, because this is part of my admin section and because of the error I'm getting.

The only issue is I don't know how I'm gonna get passed that

0 likes
2 replies

Please or to participate in this conversation.