Home  »  LibrariesNewsProgrammingTechnology   »   Laravel 8.22 Release With new Event Fake Assertion Announced

Laravel 8.22 Release With new Event Fake Assertion Announced

Laravel 8.22 release with a new event fake assertion, a collection method to reduce associative arrays to a single value has been announced.

This new release also comes with several fixes and improvements.

Laravel 8.22 comes with a new assertion assertNothingDispatched() to Event::fake() mock. Currently, all the assertion for Events require a specific event to be provided, this will catch “any” event. See example:

[php]
Event::fake();

foo(false); // Function that should NOT dispatch any event

Event::assertNothingDispatched();
[/php]

Add reduce with keys to collections and lazy collections features adds the method reduceWithKeys to Collections and LazyCollections.

Similar to map and mapWithKeys, this augments reduce to pass associative arrays’ keys to its callback. We can’t do that currently because PHP‘s array_reduce doesn’t pass array keys to its callback. See example:

[php]
$data = collect([
‘name’ => ‘Mo Khosh’,
‘username’ => ‘mokhosh’,
]);

return $data->reduceWithKeys(function($carry, $value, $key) {
return $carry . $key . ‘: ‘ . $value . PHP_EOL;
});
[/php]

Fixes in this release include a fixed error from missing null check on PHP 8 in Illuminate\Validation\Concerns\ValidatesAttributes::validateJson(). A bug with RetryCommand can happen if retryUntil doesn’t return a DateTimeInterface object but rather an integer timestamp or null.

Issues in Illuminate\Testing\PendingCommand::expectsTable() have been fixed as is the same with morphTo() attempting to map an empty string morph type to an instance.

For these and more about Laravel 8.22 release please visit the changelog here.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Libraries, News, Programming, Technology