An N+1 fixed by eager loading can be replaced by a memory problem, and a query-count assertion reports the page as healthy while it hydrates forty thousand objects.
public function testTheExportStreamsRatherThanBuffers(): void
{
factory(Order::class, 5000)->create();
$before = memory_get_peak_usage(true);
$this->artisan('export:monthly')->assertExitCode(0);
$this->assertLessThan(
64 * 1048576,
memory_get_peak_usage(true) - $before,
'the export is buffering again'
);
}
Peak rather than current is the measurement, because the whole point is the high-water mark during the run. true as the argument reports memory allocated from the system rather than by PHP, which is the number that matters for a limit. Five thousand rows is what makes the assertion meaningful — with fifty, a buffering implementation passes comfortably.