From 932b44b5041e7244c1d49d7e8a34d61245a760ab Mon Sep 17 00:00:00 2001 From: Andrew Broberg Date: Wed, 26 Nov 2025 08:42:37 +1100 Subject: [PATCH] return the brevo api response --- src/BrevoEmailChannel.php | 4 ++-- src/BrevoSmsChannel.php | 4 ++-- tests/BrevoEmailChannelTest.php | 14 ++++++++++++-- tests/BrevoSmsChannelTest.php | 15 +++++++++++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/BrevoEmailChannel.php b/src/BrevoEmailChannel.php index 8e244b4..32b70d4 100644 --- a/src/BrevoEmailChannel.php +++ b/src/BrevoEmailChannel.php @@ -15,10 +15,10 @@ public function __construct(protected readonly BrevoService $brevoService) {} /** * @throws BrevoException */ - public function send(Model|AnonymousNotifiable $notifiable, Notification $notification): void + public function send(Model|AnonymousNotifiable $notifiable, Notification $notification): array { $email = $notification->toBrevoEmail($notifiable); // @phpstan-ignore-line - $this->brevoService->sendEmail($email); + return $this->brevoService->sendEmail($email); } } diff --git a/src/BrevoSmsChannel.php b/src/BrevoSmsChannel.php index 9d59ec2..e5cfc0b 100644 --- a/src/BrevoSmsChannel.php +++ b/src/BrevoSmsChannel.php @@ -15,10 +15,10 @@ public function __construct(protected readonly BrevoService $brevoService) {} /** * @throws BrevoException */ - public function send(Model|AnonymousNotifiable $notifiable, Notification $notification): void + public function send(Model|AnonymousNotifiable $notifiable, Notification $notification): array { $sms = $notification->toBrevoSms($notifiable); // @phpstan-ignore-line - $this->brevoService->sendSms($sms); + return $this->brevoService->sendSms($sms); } } diff --git a/tests/BrevoEmailChannelTest.php b/tests/BrevoEmailChannelTest.php index 9c2931c..abc9d40 100644 --- a/tests/BrevoEmailChannelTest.php +++ b/tests/BrevoEmailChannelTest.php @@ -9,10 +9,18 @@ use YieldStudio\LaravelBrevoNotifier\Tests\User; it('send notification via BrevoEmailChannel should call BrevoService sendEmail method', function () { - $mock = $this->mock(BrevoService::class)->shouldReceive('sendEmail')->once(); + $httpResponse = [ + 'messageId' => '<201906041124.44340027797@smtp-relay.mailin.fr>', + ]; + + $mock = $this->mock(BrevoService::class) + ->shouldReceive('sendEmail') + ->once() + ->andReturn($httpResponse); + $channel = new BrevoEmailChannel($mock->getMock()); - $channel->send(new User, new class extends Notification + $response = $channel->send(new User, new class extends Notification { public function via() { @@ -24,4 +32,6 @@ public function toBrevoEmail(User $notifiable): BrevoEmailMessage return new BrevoEmailMessage; } }); + + expect($response)->toEqual($httpResponse); }); diff --git a/tests/BrevoSmsChannelTest.php b/tests/BrevoSmsChannelTest.php index c3fa68a..77076c8 100644 --- a/tests/BrevoSmsChannelTest.php +++ b/tests/BrevoSmsChannelTest.php @@ -4,15 +4,22 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notification; +use Illuminate\Support\Facades\Notification as FacadesNotification; use YieldStudio\LaravelBrevoNotifier\BrevoService; use YieldStudio\LaravelBrevoNotifier\BrevoSmsChannel; use YieldStudio\LaravelBrevoNotifier\BrevoSmsMessage; use YieldStudio\LaravelBrevoNotifier\Tests\User; it('send notification via BrevoChannel should call BrevoService sendSms method', function () { - $mock = $this->mock(BrevoService::class)->shouldReceive('sendSms')->once(); + $mock = $this->mock(BrevoService::class)->shouldReceive('sendSms') + ->once() + ->andReturn(['messageId' => 123]); + $channel = new BrevoSmsChannel($mock->getMock()); - $channel->send(new User, new class extends Notification + + FacadesNotification::fake(); + + $response = $channel->send(new User, new class extends Notification { public function via() { @@ -24,4 +31,8 @@ public function toBrevoSms(Model $notifiable): BrevoSmsMessage return new BrevoSmsMessage; } }); + + expect($response)->toEqual([ + 'messageId' => 123, + ]); });