From 7b534b47965b4d80fab8c4ab6334e4d2a7f42d84 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 28 Feb 2020 12:14:51 +1100 Subject: [PATCH 1/4] Expose Laravel Notification Id within Message Data --- src/Illuminate/Notifications/Channels/MailChannel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index 23a17ffd9918..d28241ac40a6 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -112,6 +112,7 @@ protected function buildView($message) protected function additionalMessageData($notification) { return [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => in_array( ShouldQueue::class, class_implements($notification) From ad3ad425111aac687174e40e1804f01d01b51f80 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 28 Feb 2020 12:41:34 +1100 Subject: [PATCH 2/4] Updating tests --- .../Notifications/SendingMailNotificationsTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php index 09864117a27c..9c5662acf54c 100644 --- a/tests/Integration/Notifications/SendingMailNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php @@ -80,6 +80,7 @@ public function testMailIsSent() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), @@ -124,6 +125,7 @@ public function testMailIsSentToNamedAddress() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), @@ -167,6 +169,7 @@ public function testMailIsSentWithSubject() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), @@ -200,6 +203,7 @@ public function testMailIsSentToMultipleAdresses() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), From e1cc28595cbb1b109af7c624273bff7d53f5fad6 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 28 Feb 2020 12:41:34 +1100 Subject: [PATCH 3/4] Fixing tests --- .../Notifications/SendingMailNotificationsTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php index 09864117a27c..b034285abbd3 100644 --- a/tests/Integration/Notifications/SendingMailNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php @@ -13,6 +13,7 @@ use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; use Mockery as m; use Orchestra\Testbench\TestCase; @@ -69,6 +70,7 @@ protected function setUp(): void public function testMailIsSent() { $notification = new TestMailNotification; + $notification->id = Str::uuid(); $user = NotifiableUser::forceCreate([ 'email' => 'taylor@laravel.com', @@ -80,6 +82,7 @@ public function testMailIsSent() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), @@ -112,6 +115,7 @@ public function testMailIsSent() public function testMailIsSentToNamedAddress() { $notification = new TestMailNotification; + $notification->id = Str::uuid(); $user = NotifiableUserWithNamedAddress::forceCreate([ 'email' => 'taylor@laravel.com', @@ -124,6 +128,7 @@ public function testMailIsSentToNamedAddress() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), @@ -156,6 +161,7 @@ public function testMailIsSentToNamedAddress() public function testMailIsSentWithSubject() { $notification = new TestMailNotificationWithSubject; + $notification->id = Str::uuid(); $user = NotifiableUser::forceCreate([ 'email' => 'taylor@laravel.com', @@ -167,6 +173,7 @@ public function testMailIsSentWithSubject() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), @@ -189,6 +196,7 @@ public function testMailIsSentWithSubject() public function testMailIsSentToMultipleAdresses() { $notification = new TestMailNotificationWithSubject; + $notification->id = Str::uuid(); $user = NotifiableUserWithMultipleAddreses::forceCreate([ 'email' => 'taylor@laravel.com', @@ -200,6 +208,7 @@ public function testMailIsSentToMultipleAdresses() $this->mailer->shouldReceive('send')->once()->with( ['html' => 'htmlContent', 'text' => 'textContent'], array_merge($notification->toMail($user)->toArray(), [ + '__laravel_notification_id' => $notification->id, '__laravel_notification' => get_class($notification), '__laravel_notification_queued' => false, ]), From b08dfcd72be56d1da4b0d45755ea6d6fd884a5c7 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 28 Feb 2020 13:10:14 +1100 Subject: [PATCH 4/4] Fixing the test for 7.3 --- .../Notifications/SendingMailNotificationsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php index b034285abbd3..3be53abc6cf7 100644 --- a/tests/Integration/Notifications/SendingMailNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php @@ -70,7 +70,7 @@ protected function setUp(): void public function testMailIsSent() { $notification = new TestMailNotification; - $notification->id = Str::uuid(); + $notification->id = Str::uuid()->toString(); $user = NotifiableUser::forceCreate([ 'email' => 'taylor@laravel.com', @@ -115,7 +115,7 @@ public function testMailIsSent() public function testMailIsSentToNamedAddress() { $notification = new TestMailNotification; - $notification->id = Str::uuid(); + $notification->id = Str::uuid()->toString(); $user = NotifiableUserWithNamedAddress::forceCreate([ 'email' => 'taylor@laravel.com', @@ -161,7 +161,7 @@ public function testMailIsSentToNamedAddress() public function testMailIsSentWithSubject() { $notification = new TestMailNotificationWithSubject; - $notification->id = Str::uuid(); + $notification->id = Str::uuid()->toString(); $user = NotifiableUser::forceCreate([ 'email' => 'taylor@laravel.com', @@ -196,7 +196,7 @@ public function testMailIsSentWithSubject() public function testMailIsSentToMultipleAdresses() { $notification = new TestMailNotificationWithSubject; - $notification->id = Str::uuid(); + $notification->id = Str::uuid()->toString(); $user = NotifiableUserWithMultipleAddreses::forceCreate([ 'email' => 'taylor@laravel.com',