Laravel notification mocking

For example, you may create a notification for project like belong:

// notification
class PostCreated extends Notification

public function via($notifiable)
return ['database']; // for this example, I used database notifiable.

public function toArray($notifiable)
return [
'post_id' => $this->post->id, //constructor object.

Next, I added the notification to service flow.

auth()->user()->notify(new PostCreated($post));

But here is a problem, how do I test it?

// PostTest.php
public function it_should_create_by_auth()
// enabled fake


// checking the flow is correct...

function ($notification, $channels) use ($post) {
return $notification->post->id === $post->id;

For now, you have tested notification and work now, it’s useful.

see documentation.