The Http::assertSent()
, Event::assertDispatched()
, and Queue::assertPushed()
) test methods are perhaps a bit unintuitive.
They seem like they would run just once and check the assertions provided in your callback.
In fact, that callback runs once for each HTTP request (or dispatched event or queued job) and it evaluates the logic inside the callback for each. So if you have 10 requests (or events or jobs) and 3 of them return true
it passes. If you have 10 requests and 9 of them return true
it passes. It only fails if none of the callbacks return true
.
So using dd($request)
in one of those assertions is only dumping out the first one and then killing the test. You might not see the one you actually need.
If you’re trying to see what data is in the request, you’re better off either doing something like Log::debug($request->body())
or ray($request->url())
1 or putting an xdebug breakpoint on the first line of the callback, running the test, and pressing the “continue” button until you get to the request you’re trying to inspect (possibly the second or fourth or tenth, depending on what happens before the one you want to inspect).
Here is a few code samples that may clarify this a bit more: