Reference
Protect important request profiles with Pest
Capture the real Laravel response, read its exact profile ID, and assert only the error or performance limits that represent stable product behavior.
Enable profiling before the test app boots
New Debug Bar defaults to the local environment. To capture profiles during tests, publish the package configuration and include testing in the allowed environments:
'environments' => ['local', 'testing'],
Read the exact profile ID from the response
Every profiled response includes X-NewDebugBar-Profile. Assert that the header exists, then pass its UUID to ProfileAssertions::stored().
Do not use “the latest profile” in a test. Related requests and background work can produce another profile after the response you meant to inspect.
Use focused profile assertions
| Assertion | Protects |
|---|---|
assertNoErrors() | No error response or exception finding |
assertNoRepeatedQueries() | No repeated normalized query pattern |
assertNoLikelyNPlusOneQueries() | No likely N+1 finding |
assertQueryCountAtMost($count) | Maximum query count |
assertQueryTimeAtMost($milliseconds) | Maximum total query time |
assertDurationAtMost($milliseconds) | Maximum full request duration |
assertPeakMemoryAtMost($megabytes) | Maximum peak memory |
Write a Pest profile test
<?php
use NewDebugBar\Testing\ProfileAssertions;
use function Pest\Laravel\get;
it('keeps the dashboard profile within its budget', function () {
$response = get('/dashboard')
->assertOk()
->assertHeader('X-NewDebugBar-Profile');
ProfileAssertions::stored(
(string) $response->headers->get('X-NewDebugBar-Profile'),
)
->assertNoErrors()
->assertQueryCountAtMost(12)
->assertNoLikelyNPlusOneQueries()
->assertDurationAtMost(300);
});
Choose budgets that describe stable behavior
- Prefer query counts and error findings when they are stable across machines.
- Give timing and memory budgets room for normal CI variation.
- Use realistic database records so a likely N+1 pattern can actually appear.
- Assert the response behavior separately; a healthy profile does not replace feature assertions.
Next step
Inspect a failing profile with an agent
Pass the exact response-header profile ID to the local MCP server for bounded findings and deeper retained evidence.
Open the MCP setup guide