想要使用PHPUnit在laravel中对松弛通知进行单元测试

时间:2020-08-28 09:17:48

标签: laravel notifications phpunit slack

请帮助我编写单元测试存根,以了解是否发送了松弛通知。在执行一批操作时,如果发生错误,我将在松弛通道中发送错误。

1 个答案:

答案 0 :(得分:0)

在测试中,您应该使用MockApplicationServices特性。它的工作原理几乎与 the documented event mocking.

用法是:

$this->expectsNotification($notifiable, $notification);

// eg.
$this->expectsNotification($user, UpperLimitExceeded::class);

还有$ this-> withoutNotifications()跳过任何遇到的通知。