I want to show you a few helper methods for debugging your failed HTTP tests.
Imagine the scenario in which you want to assert the Forbidden status. But instead of getting an error Expected response status code [403] but received 200.
, you receive a normal status 200. It could mean there's a Middleware problem or wrong permissions added.
But what is inside that 200, and how does that page actually look? How do you debug those internal parts?
In the test, you load the page and call assertForbidden()
, so you don't see the actual response's content.
use function Pest\Laravel\actingAs; beforeEach(function (): void { $this->user = User::factory()->create();}); test('guest cannot access products page', function () { actingAs($this->user) ->get('/products/create') ->assertForbidden();});
You can use the dd()
method on...