Skip to content

[12.x] - add dispatchedOnce methods #56494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2025

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