-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
FailedJobMonitorTest.php
77 lines (57 loc) · 2.24 KB
/
FailedJobMonitorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Spatie\FailedJobMonitor\Test;
use Illuminate\Queue\Events\JobFailed;
use Spatie\FailedJobMonitor\Notifiable;
use Spatie\FailedJobMonitor\Notification;
use Spatie\FailedJobMonitor\Test\Dummy\Job;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Spatie\FailedJobMonitor\Test\Dummy\AnotherNotifiable;
use Spatie\FailedJobMonitor\Test\Dummy\AnotherNotification;
use Illuminate\Support\Facades\Notification as NotificationFacade;
class FailedJobMonitorTest extends TestCase
{
use DatabaseMigrations;
/** @var \Spatie\FailedJobMonitor\Test\Dummy\TestQueueManager */
protected $manager;
public function setUp()
{
parent::setUp();
NotificationFacade::fake();
}
/** @test */
public function it_can_send_notification_when_a_job_failed()
{
$this->fireFailedEvent();
NotificationFacade::assertSentTo(new Notifiable(), Notification::class);
}
/** @test */
public function it_can_send_notification_when_job_failed_to_different_notifiable()
{
$this->app['config']->set('failed-job-monitor.notifiable', AnotherNotifiable::class);
$this->fireFailedEvent();
NotificationFacade::assertSentTo(new AnotherNotifiable(), Notification::class);
}
/** @test */
public function it_can_send_notification_when_job_failed_to_different_notification()
{
$this->app['config']->set('failed-job-monitor.notification', AnotherNotification::class);
$this->fireFailedEvent();
NotificationFacade::assertSentTo(new Notifiable(), AnotherNotification::class);
}
/** @test */
public function it_filters_out_notifications_when_the_notificationFilter_returns_false()
{
$this->app['config']->set('failed-job-monitor.callback', [$this, 'returnsFalseWhenExceptionIsEmpty']);
$this->fireFailedEvent();
NotificationFacade::assertNotSentTo(new Notifiable(), AnotherNotification::class);
}
protected function fireFailedEvent()
{
return event(new JobFailed('test', new Job(), new \Exception()));
}
public function returnsFalseWhenExceptionIsEmpty($notification)
{
$message = $notification->getEvent()->exception->getMessage();
return ! empty($message);
}
}