Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BrevoEmailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/BrevoSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 12 additions & 2 deletions tests/BrevoEmailChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -24,4 +32,6 @@ public function toBrevoEmail(User $notifiable): BrevoEmailMessage
return new BrevoEmailMessage;
}
});

expect($response)->toEqual($httpResponse);
});
15 changes: 13 additions & 2 deletions tests/BrevoSmsChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -24,4 +31,8 @@ public function toBrevoSms(Model $notifiable): BrevoSmsMessage
return new BrevoSmsMessage;
}
});

expect($response)->toEqual([
'messageId' => 123,
]);
});