我有一个WelcomeNotification
实现了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
}
}
如何测试此通知是否已推送到队列?
我正在尝试像这样测试它,但是我正在
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' => 'john@test.com','password' => 'passwordtest',]);
Queue::assertPushed(WelcomeNotification::class);
}
在我在RegisterController
中注册的功能内:
protected function registered(Request $request,$user)
{
$user->notify(new WelcomeNotification());
// other code
}
我已经成功断言了使用WelcomeNotification
注册时已正确地将Notification::assertSentTo
发送给用户。
我的问题是如何测试WelcomeNotification
是否被推入队列?