Skip to content
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

[9.x] Add NotificationFake::assertNothingSentTo() #41232

Merged
merged 2 commits into from
Feb 24, 2022
Merged

[9.x] Add NotificationFake::assertNothingSentTo() #41232

merged 2 commits into from
Feb 24, 2022

Conversation

axlon
Copy link
Contributor

@axlon axlon commented Feb 24, 2022

Right now there is no easy way to assert that no notifications have been sent to a specific notifiable. Laravel does allow you to assert that no notifications have been sent at all, but this isn't always applicable.

This is primarily an issue when a piece of code dispatches various notification types to different notifiables, for example:

$uploader = User::factory()->createOne();
$podcast = Podcast::factory()->for($uploader)->createOne();
$episode = PodcastEpisode::factory()->for($podcast)->createOne();

$subscriber = User::factory()->hasAttached($podcast)->createOne();
$randomUser = User::factory()->createOne();

Bus::dispatchSync(new ProcessPodcast($episode));

Notification::assertSentTo($uploader, EpisodeProcessed::class);
Notification::assertSentTo($subscriber, NewEpisodeAvailable::class);

Notification::assertNotSentTo($randomUser, EpisodeProcessed::class);
Notification::assertNotSentTo($randomUser, NewEpisodeAvailable::class);

The example above is quite simple and only sends 2 notifications, but the number of calls to assertNotSentTo would increase by one for every additional notification type that is dispatched.

This PR aims to simplify testing in these kinds of scenario's by adding Notification::assertNothingSentTo($notifiable)

PS. This PR includes a test for NotificationFake::assertNothingSent(), which appeared to be missing

@taylorotwell taylorotwell merged commit 29f5cac into laravel:9.x Feb 24, 2022
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