Laravel 13.35 New Published on

Checking an event's contents with an array of properties

assertDispatched() and assertPushed() accept an array of expected properties instead of a callback.

Topics covered: TestingEventsQueues

New in Laravel 13.35. To check what a faked event or job carries, you had to pass a callback that inspects the object and returns true. The assertions of the Event, Queue, Bus and Notification fakes now accept an array of expected properties.

Before

Event::assertDispatched(CommandePassee::class, function (CommandePassee $event) {
    return $event->number === 'ORD-A12' && $event->total === 2550;
});

Since Laravel 13.35

Event::assertDispatched(CommandePassee::class, ['number' => 'ORD-A12', 'total' => 2550]);

Each listed property is compared strictly (===): 2550 is not '2550'. An Eloquent model is compared with is(), so by its key. Properties you don't list don't count.

Your task

POST /api/orders announces the order (CommandePassee, “order placed”) and queues the preparation of the parcel (PreparerColis, “prepare parcel”). The test in tests/Feature/CommandeTest.php checks that they go out, but not what they contain. Strengthen it by passing each assertion the array of expected properties. Every mutant must make your tests fail.

Where the feature comes from: the original pull request.