From 6695693e673ceeaa7a0a53e6b8ed8f5b2a4a9408 Mon Sep 17 00:00:00 2001 From: yaozm Date: Wed, 8 May 2024 16:30:22 +0800 Subject: [PATCH] test(MailChannelTest): Add test case for sending report email - Added test case for sending report email in MailChannelTest - Imported necessary classes and facades - Faked Mail facade - Asserted that ReportExceptionMail was sent --- src/Channels/MailChannel.php | 2 +- src/Events/ExceptionReportedEvent.php | 2 ++ tests/Channels/MailChannelTest.php | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Channels/MailChannel.php b/src/Channels/MailChannel.php index 22e5943..46d0a39 100644 --- a/src/Channels/MailChannel.php +++ b/src/Channels/MailChannel.php @@ -55,7 +55,7 @@ static function (object $mailerOrPendingMail, array $parameters, string $method) return \is_object($object) ? $object : $mailerOrPendingMail; }, - Mail::driver($this->config->get('mailer')) + Mail::mailer($this->config->get('mailer')) ); if ($this->config->has('extender')) { diff --git a/src/Events/ExceptionReportedEvent.php b/src/Events/ExceptionReportedEvent.php index 567c8b1..fd13b9d 100644 --- a/src/Events/ExceptionReportedEvent.php +++ b/src/Events/ExceptionReportedEvent.php @@ -24,6 +24,8 @@ class ExceptionReportedEvent /** * @noinspection MissingParameterTypeDeclarationInspection + * + * @param mixed $result */ public function __construct(Channel $channel, $result) { diff --git a/tests/Channels/MailChannelTest.php b/tests/Channels/MailChannelTest.php index bd7e701..4a31e76 100644 --- a/tests/Channels/MailChannelTest.php +++ b/tests/Channels/MailChannelTest.php @@ -15,6 +15,8 @@ */ use Guanguans\LaravelExceptionNotify\ExceptionNotifyManager; +use Guanguans\LaravelExceptionNotify\Mail\ReportExceptionMail; +use Illuminate\Support\Facades\Mail; it('will throw `InvalidArgumentException`', function (): void { config()->set('exception-notify.channels.mail.extender', null); @@ -28,5 +30,7 @@ static fn (object $mailerOrPendingMail): object => $mailerOrPendingMail ); + Mail::fake(); $this->app->make(ExceptionNotifyManager::class)->driver('mail')->report('report'); -})->group(__DIR__, __FILE__)->throws(Swift_TransportException::class); + Mail::assertSent(ReportExceptionMail::class); +})->group(__DIR__, __FILE__);