From edb333016bd583e900395b1fb42c5f18bf6a2d49 Mon Sep 17 00:00:00 2001 From: Martin Hansen Date: Tue, 9 Jun 2020 23:10:10 +0200 Subject: [PATCH] Fix channel type of NotificationFailed events This commit changes the channel property that is set on the dispatched NotificationFailed events from a class instance to a string representing the class name. This is done because the property is documented as a string property on Illuminate's side, and if an application assumes that this package adheres to that documentation, runtime errors may occur. --- src/ApnChannel.php | 2 +- tests/ApnChannelTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ApnChannel.php b/src/ApnChannel.php index 9a28de1..8b5b0c7 100644 --- a/src/ApnChannel.php +++ b/src/ApnChannel.php @@ -96,7 +96,7 @@ protected function dispatchEvents($notifiable, $notification, array $responses) continue; } - $event = new NotificationFailed($notifiable, $notification, $this, [ + $event = new NotificationFailed($notifiable, $notification, static::class, [ 'id' => $response->getApnsId(), 'token' => $response->getDeviceToken(), 'error' => $response->getErrorReason(), diff --git a/tests/ApnChannelTest.php b/tests/ApnChannelTest.php index ca30873..35a082f 100644 --- a/tests/ApnChannelTest.php +++ b/tests/ApnChannelTest.php @@ -62,4 +62,23 @@ public function it_dispatches_events_for_failed_notifications() $this->channel->send(new TestNotifiable, new TestNotification); } + + /** @test */ + public function it_dispatches_failed_notification_events_with_correct_channel() + { + $this->events->shouldReceive('dispatch') + ->withArgs(function (NotificationFailed $notificationFailed) { + return $notificationFailed->channel === ApnChannel::class; + }); + + $this->client->shouldReceive('addNotification'); + $this->client->shouldReceive('push') + ->once() + ->andReturn([ + new Response(200, 'headers', 'body'), + new Response(400, 'headers', 'body'), + ]); + + $this->channel->send(new TestNotifiable, new TestNotification); + } }