Laravel 13.35 has introduced support for key-value property arrays inside testing fakes, eliminating the need to write custom callback closures when verifying properties on queued jobs, dispatched events, bus commands, and sent notifications.
Cleaner Test Assertions
Instead of defining multi-line closure functions to inspect job or event parameters during automated testing, developers using Laravel 13.35 can now supply a clean associative array of expected property names and values. This intuitive property array syntax works seamlessly across the framework's Queue, Bus, Event, and Notification fakes.
The simplified array syntax also applies to negative and variant assertion methods throughout the testing suite, including assertNotPushed, assertPushedOn, assertNotDispatched, and assertNotSentTo. Developers simply supply the target class name as the first parameter and the expected property array as the second argument, significantly streamlining assertions across complex test suites.
Strict Equality and Eloquent Model Checks
Under the hood, the new array assertion mechanism evaluates each top-level key using strict equality comparison (===). However, when comparing Eloquent model instances, Laravel automatically delegates the verification to the model's dedicated $model->is() method, which confirms matching database connections, primary keys, and table names.
Because standard non-model values depend strictly on identity matching, object instances such as Carbon dates or custom collections cannot be checked directly within the basic property array. For relative date comparisons, deeply nested data structures, or collection assertions, developers must continue relying on traditional closure callbacks.
Public Property Constraints
The fake underlying implementation reads properties directly from outside the target class instance, requiring all checked fields to be defined as public. Modern PHP constructor property promotion natively supports this structure, whereas jobs or events relying on protected fields or getter methods must still utilize closure assertions.
If an assertion array includes a property key that does not actually exist on the inspected target object, Laravel fails the assertion explicitly rather than raising a PHP runtime error. The framework enhancement was originally contributed by developer Jack Bayliss in pull request #61770.
AI-generated editorial illustration; not a documentary photograph.
Source: Laravel Fake Assertions Now Accept Property Arrays

Leave a Reply