🚀 Available for Freelance, Remote, and Full-Time Opportunities. Let's build something amazing together.

Laravel Tutorials
1 min read

Laravel Fake Assertions Now Accept Property Arrays

Simplify event, job, and notification testing by passing direct associative arrays to Laravel's testing assertions.

A

Author

3 weeks ago

Laravel Fake Assertions Now Accept Property Arrays

Writing testing callbacks with Event::assertDispatched(function ($event) { return ...; }) can quickly become tedious when you only want to assert that two or three model properties match.

Compact Assertions

You can now pass an array of expected property values directly into your assertion methods:

use App\Events\OrderPlaced;
use App\Models\Order;
use Illuminate\Support\Facades\Event;

Event::fake();

// Action triggering event
Order::create(['id' => 101, 'status' => 'confirmed']);

// Cleaner assertion syntax:
Event::assertDispatched(OrderPlaced::class, [
    'orderId' => 101,
    'status'  => 'confirmed',
]);

This syntax makes testing suites significantly more readable, concise, and easier to maintain across large engineering teams.