Summer Sale! All accounts are 50% off this week.

bwrigley's avatar

Seeding Notifications?

I think I'm probably thinking about this wrong but I would like to seed my database with notifications for testing.

I have various front-end components that display unreadNotifications() counts and links to view them etc.

However, I can't seem to find a way to create notifications without actually triggering my Pusher broadcasts.

Notification::fake() doesn't seem to create a database entry.

Am I going about this the wrong way?

0 likes
8 replies
DhPandya's avatar

@bwrigley You have to trigger your event. That is the only way to trigger your pusher notification.

event(new YourClassName())

bwrigley's avatar

@DhPandya thanks for the reply!

For my tests I don't want to actually trigger the events mail, broadcast etc. I just want to create entries in the database so I verify they are being accessed and displayed correctly.

bwrigley's avatar

@DhPandya That would be great, but there is no Notitication model to create a factory from. Or are you suggesting a different way to create them?

bwrigley's avatar

@DhPandya the problem I have is that when I use Notification::Fake() that prevents creating the database entries.

I want to be able to call $user->notifications() and return a list of seeded notifications to test with.

Please or to participate in this conversation.