No release, weekly updates, and tip

No release

There were a few patch releases last week, but no release this week so far as I believe Taylor was at re:Invent.

Weekly Journal

Last week I did a series of livestreams to say thanks to Laravel. It was a combination of addressing a few papercuts, as well as an attempt to add a couple features. I was 50-50 on the PRs. Two got merged. One didn't. And the other was a little more involved than I expected.

As a tangent, I found the comments in the PRs interesting. It seems any features around HTTP status codes are met with dislike. You'd think Laravel, as a web framework, would have amazing DX to make responding with HTTP status codes a breeze. But the most expressive it has is response()->noContent().

Anyway, I plan to revisit these other features. I'll likely wrap them up into my own package. So, if nothing else, a package will make them easier to share in my own projects. But if you like the too, they're available.

The rest of the week was a holiday. I did manage to hack during the girl's nap time. I've wanted to explore Cloudflare's offerings more. So I started by moving my static sites to Cloudflare Pages. These were mostly blogs built with Jigsaw or HydePHP. Now they're running free, in the cloud and I even removed an old nginx server.

This week I hope to finish up the side-project with JT. If we do, we'll probably launch next week.

Weekly Tip

This is something I spoke about in my talk at Laracon US 2023, but I stumbled upon it again in writing tests for our side-project.

There are two gotchas when testing the following code:

broadcast(new FirstContributorsProcessed($this->range));

First, although it uses the broadcast() helper, this actually dispatches an event. So to test this, there is no Broadcast::fake(). Instead, you use the Event::fake() and its assertions to verify your event was broadcast.

Event::fake();
 
// ...
 
Event::assertDispatched(
FirstContributorsProcessed::class,
fn ($event) => $event->range->id($range)
);

The next gotcha is when using Event::fake() like this, you now fake all events. This includes internal events, such as those fired by Eloquent or Jobs. No events will actually fire. Which may not be what you want.

So, when you need to fake an event, my suggestion is to pass the first argument to Event::fake(). This strictly sets the events you want to prevent from firing and verify in your test case. Allowing other events to fire normally.

For example, the code rewritten above would now allow all other events to fire within the application, but the FirstContributorsProcessed event would not.

Event::fake([FirstContributorsProcessed::class]);
 
// ...
 
Event::assertDispatched(
FirstContributorsProcessed::class,
fn ($event) => $event->range->id($range)
);