Skip to content

Commit

Permalink
test(MailChannelTest): Add test case for sending report email
Browse files Browse the repository at this point in the history
- Added test case for sending report email in MailChannelTest
- Imported necessary classes and facades
- Faked Mail facade
- Asserted that ReportExceptionMail was sent
  • Loading branch information
guanguans committed May 8, 2024
1 parent 1b0461b commit 6695693
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 2 additions & 0 deletions src/Events/ExceptionReportedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ExceptionReportedEvent

/**
* @noinspection MissingParameterTypeDeclarationInspection
*
* @param mixed $result
*/
public function __construct(Channel $channel, $result)
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Channels/MailChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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__);

0 comments on commit 6695693

Please sign in to comment.