Courses

Testing in Laravel 11: Advanced Level

Debugging with dd() and dump()

Summary of this lesson:
- Use dd() and dump() methods for test debugging
- Inspect HTTP response content
- Dump headers and session information
- Understand different debugging techniques
- Improve test error investigation

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...

The full lesson is only for Premium Members.
Want to access all 31 lessons of this course? (74 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord