I have a WelcomeNotification which implements ShouldQueue
class WelcomeNotification extends Notification implements ShouldQueue
{
use Queueable;
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
// send a welcome message to the user via mailtrap
}
}
How can I test if this notification has been pushed to the queue?
I am trying to test it like this but I am getting
The expected [App\Notifications\WelcomeNotification] job was not pushed
/** @test */
public function welcome_notification_is_pushed_to_queue()
{
Queue::fake();
$this->post(route('register'), [
'name' => 'John Doe',
'email' => '[email protected]',
'password' => 'passwordtest',
]);
Queue::assertPushed(WelcomeNotification::class);
}
Inside my registered function in RegisterController:
protected function registered(Request $request, $user)
{
$user->notify(new WelcomeNotification());
// other code
}
I have successfully asserted that WelcomeNotification is correctly being sent to the user when registering using Notification::assertSentTo.
My issue is how to test if WelcomeNotification was pushed to the queue or not?