Laravel 8.22 Released
Published on by Paul Redmond
The Laravel team released 8.22 yesterday with a new event fake assertion, a collection method to reduce associative arrays to a single value, and the latest changes in the 8.x branch:
Assert Nothing Dispatched
@danilopolani contributed event assertion assertNothingDispatched
to the fake event instance:
Event::fake(); // Function that should NOT dispatch any eventEvent::assertNothingDispatched();
Reduce with Keys Collection Method
Mo Khosh contributed a reduceWithKeys
method to collections (and lazy collections) to reduce an associative collection to a single value.
Similar to
map
andmapWithKeys
, this augmentsreduce
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.
Here’s an example from the pull request:
$data = collect([ 'name' => 'Mo Khosh', 'username' => 'mokhosh',]); return $data->reduceWithKeys(function($carry, $value, $key) { return $carry . $key . ': ' . $value . PHP_EOL;});
Release Notes
You can see the full list of new features and updates below and the diff between 8.21.0 and 8.22.0 on GitHub. The following release notes are directly from the changelog:
v8.22.0
Added
- Added new lines to
DetectsLostConnections
(#35752, #35790) - Added
Fakes\EventFake::assertNothingDispatched()
(#35835) - Added reduce with keys to collections and lazy collections (#35839)
Fixed
- Fixed error from missing null check on PHP 8 in
Validation\Concerns\ValidatesAttributes::validateJson()
(#35797) - Fix bug with RetryCommand (4415b94, #35828)
- Fixed
Illuminate\Testing\PendingCommand::expectsTable()
(#35820) - Fixed
morphTo()
attempting to map an empty string morph type to an instance (#35824)