Laravel 8.22 Released

News

January 13th, 2021

Laravel 8.22 Released

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 event
Event::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 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.

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)

Changes

  • Update Illuminate\Http\Resources\CollectsResources::collects() (1fa20dd)
  • “null” constraint prevents aliasing SQLite ROWID (#35792)
  • Allow strings to be passed to the report function (#35803)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.