From 44f00c9a52d6999d6b1908969063824e370b5ae4 Mon Sep 17 00:00:00 2001 From: Thomas Arrow Date: Tue, 31 Oct 2023 12:36:17 +0000 Subject: [PATCH] minimal example of testing simple job that emails a simple notification --- app/Jobs/SendSimpleNotificationJob.php | 37 ++++++++++++ app/Notifications/SimpleNotification.php | 61 ++++++++++++++++++++ tests/Unit/SendSimpleNotificationJobTest.php | 30 ++++++++++ tests/Unit/SimpleNotificationTest.php | 28 +++++++++ 4 files changed, 156 insertions(+) create mode 100644 app/Jobs/SendSimpleNotificationJob.php create mode 100644 app/Notifications/SimpleNotification.php create mode 100644 tests/Unit/SendSimpleNotificationJobTest.php create mode 100644 tests/Unit/SimpleNotificationTest.php diff --git a/app/Jobs/SendSimpleNotificationJob.php b/app/Jobs/SendSimpleNotificationJob.php new file mode 100644 index 000000000..78bc88baf --- /dev/null +++ b/app/Jobs/SendSimpleNotificationJob.php @@ -0,0 +1,37 @@ +user = $user; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $this->user->notify(new SimpleNotification()); + } +} diff --git a/app/Notifications/SimpleNotification.php b/app/Notifications/SimpleNotification.php new file mode 100644 index 000000000..548182738 --- /dev/null +++ b/app/Notifications/SimpleNotification.php @@ -0,0 +1,61 @@ +line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/tests/Unit/SendSimpleNotificationJobTest.php b/tests/Unit/SendSimpleNotificationJobTest.php new file mode 100644 index 000000000..866c8ddd6 --- /dev/null +++ b/tests/Unit/SendSimpleNotificationJobTest.php @@ -0,0 +1,30 @@ + 'foobar@example.com', 'password' => 'asdf']); + $job = new SendSimpleNotificationJob($user); + $job->handle(); + Notification::assertSentTo($user, SimpleNotification::class); + } +} diff --git a/tests/Unit/SimpleNotificationTest.php b/tests/Unit/SimpleNotificationTest.php new file mode 100644 index 000000000..4c386f0a6 --- /dev/null +++ b/tests/Unit/SimpleNotificationTest.php @@ -0,0 +1,28 @@ + 'foobar@example.com', 'password' => 'asdf']); + $user->notify($notification); + Notification::assertSentTo($user, SimpleNotification::class); + } +}