Skip to content

Conversation

@lioneaglesolutions
Copy link
Contributor

@lioneaglesolutions lioneaglesolutions commented Jul 31, 2025

When using the assertDispatchedTimes method, it can be confusing because the default parameter is 1.

Sometimes we want to know that something was dispatched exactly once and be able to easily read this at a glance.

Currently you could just do:

Event::assertDispatchTimes($myEvent, 1);

However some tools remove the 1 as it is "dead code" due to 1 being the default argument. So it becomes:

Event::assertDispatchTimes($myEvent);

This reads like an unfinished sentence.

This PR adds:

Event::assertDispatchedOnce(...)

This is very explicit and easy to read.

@taylorotwell
Copy link
Member

Your methods should just call assertDispatchTimes internally so we don't duplicate all the code.

@taylorotwell taylorotwell marked this pull request as draft August 3, 2025 15:05
@lioneaglesolutions
Copy link
Contributor Author

@taylorotwell done!

@lioneaglesolutions lioneaglesolutions marked this pull request as ready for review August 3, 2025 20:25
@taylorotwell taylorotwell merged commit b4021b4 into laravel:12.x Aug 4, 2025
60 checks passed
AhmedAlaa4611 referenced this pull request in laravel/docs Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants