Laravel 9.12, weekly updates, and 🔥 tip

Laravel 9.12

Back to our regular Tuesday release this week bringing us to Laravel 9.12. Here are some highlights:

  • Add assertThrows for testing exceptions in #42155
  • Ability to require all Http requests be faked in #42230
  • Defer expanding callables on Factories in #42241
  • Added throwIf to PendingRequest in #42260
  • Allow passing key/value arrays to getArguments and getOptions in #42268
  • Add whereNotMorphedTo and orWhereNotMorphedTo to Eloquent in #42264
  • Add onLastPage to CursorPaginator in #42301
  • Enable to modify Http request headers with beforeSending callback in #42244

You may review the full branch diff on GitHub for a complete list of changes.

This version bump and update is automated for subscribers to a Shifty Plan. If you don't have one of those, be sure to bump your constraint and run composer update to get the latest features.

Weekly Journal

Last week I finished updating the Laravel Linter, Laravel Fixer, Upgrade Checker, and Tests Generator to require Laravel 9 as a minimum. This allows me to use all the latest conventions and drop some of the older detections which, at this point, likely added noise to the PR.

I finished up the Human Shifts which came in last week. Of course, I have a new one which came in yesterday. So later this week I update that from Laravel 5.6 to Laravel 9.x.

Today I spent some time upgrading my additional projects still running Laravel 8.x. I live-streamed using Shift to do so. Now that everything is running Laravel 9.x, I'll upgrade all my servers to PHP 8.1.

I also paired with Jess Archer this morning on some outstanding Shift bugs. It's been a while since she joined the Laravel team. So it was nice to pair again. I'll work to finish squashing those this week as well.

🔥 Tip

I was glad to see the preventStrayRequests addition from Tim McDonald got added to the Http testing layer.

I learned this the hard way when I actually had an additional (errant) request in my code. Unfortunately my tests passed.

Of course, I found out otherwise pretty quickly in production. The test, in this case, gave my false confidence. I assumed the Http fake would only work for the requests I faked. While true, it also worked for the requests I didn't fake.

I advocate for being strict in tests for this exact reason. It takes a little more work sometimes, but is often worth it. So I'll be adding Http::preventStrayRequests(); to my test cases from here on. 🔥