File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 22
33namespace NotificationChannels \PusherPushNotifications ;
44
5- use Illuminate \Notifications \Events \NotificationFailed ;
6- use Illuminate \Notifications \Notification ;
75use Pusher ;
6+ use Illuminate \Events \Dispatcher ;
7+ use Illuminate \Notifications \Notification ;
8+ use Illuminate \Notifications \Events \NotificationFailed ;
89
910class PusherChannel
1011{
11- /** @var Pusher */
12+ /**
13+ * @var \Pusher
14+ */
1215 protected $ pusher ;
1316
17+ /**
18+ * @var \Illuminate\Events\Dispatcher
19+ */
20+ private $ events ;
21+
1422 /**
1523 * @param \Pusher $pusher
1624 */
17- public function __construct (Pusher $ pusher )
25+ public function __construct (Pusher $ pusher, Dispatcher $ events )
1826 {
1927 $ this ->pusher = $ pusher ;
28+ $ this ->events = $ events ;
2029 }
2130
2231 /**
@@ -26,7 +35,6 @@ public function __construct(Pusher $pusher)
2635 * @param \Illuminate\Notifications\Notification $notification
2736 *
2837 * @return void
29- * @throws \NotificationChannels\PusherPushNotifications\Exceptions\CouldNotSendNotification
3038 */
3139 public function send ($ notifiable , Notification $ notification )
3240 {
@@ -40,7 +48,9 @@ public function send($notifiable, Notification $notification)
4048 );
4149
4250 if (! in_array ($ response ['status ' ], [200 , 202 ])) {
43- event (new NotificationFailed ($ notifiable , $ notification , $ response ));
51+ $ this ->events ->fire (
52+ new NotificationFailed ($ notifiable , $ notification , $ response )
53+ );
4454 }
4555 }
4656
Original file line number Diff line number Diff line change 22
33namespace NotificationChannels \PusherPushNotifications \Test ;
44
5+ use Illuminate \Events \Dispatcher ;
6+ use Illuminate \Notifications \Events \NotificationFailed ;
57use Illuminate \Notifications \Notifiable ;
68use NotificationChannels \PusherPushNotifications \PusherChannel ;
79use Illuminate \Notifications \Notification ;
@@ -16,7 +18,9 @@ public function setUp()
1618 {
1719 $ this ->pusher = Mockery::mock (Pusher::class);
1820
19- $ this ->channel = new PusherChannel ($ this ->pusher );
21+ $ this ->events = Mockery::mock (Dispatcher::class);
22+
23+ $ this ->channel = new PusherChannel ($ this ->pusher , $ this ->events );
2024
2125 $ this ->notification = new TestNotification ;
2226
@@ -41,6 +45,20 @@ public function it_can_send_a_notification()
4145
4246 $ this ->channel ->send ($ this ->notifiable , $ this ->notification );
4347 }
48+
49+ /** @test */
50+ public function it_fires_failure_event_on_failure ()
51+ {
52+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiable );
53+
54+ $ data = $ message ->toArray ();
55+
56+ $ this ->pusher ->shouldReceive ('notify ' )->with ('interest_name ' , $ data , true )->andReturn (['status ' => 500 ]);
57+
58+ $ this ->events ->shouldReceive ('fire ' )->with (Mockery::type (NotificationFailed::class));
59+
60+ $ this ->channel ->send ($ this ->notifiable , $ this ->notification );
61+ }
4462}
4563
4664class TestNotifiable
You can’t perform that action at this time.
0 commit comments