From 6f894af96a41e046f1cd1f203c69d2ea65368f56 Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Fri, 16 Aug 2024 11:25:00 +0200 Subject: [PATCH 1/3] feat: Throw exception when template id don't exist on Brevo --- src/BrevoEmailChannel.php | 1 + src/BrevoService.php | 8 ++++++++ src/BrevoSmsChannel.php | 1 + src/{ => Exceptions}/BrevoException.php | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) rename src/{ => Exceptions}/BrevoException.php (89%) diff --git a/src/BrevoEmailChannel.php b/src/BrevoEmailChannel.php index 8e244b4..090907e 100644 --- a/src/BrevoEmailChannel.php +++ b/src/BrevoEmailChannel.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\Notification; +use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException; class BrevoEmailChannel { diff --git a/src/BrevoService.php b/src/BrevoService.php index 778afc1..02c48c0 100644 --- a/src/BrevoService.php +++ b/src/BrevoService.php @@ -6,6 +6,7 @@ use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Facades\Http; +use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException; class BrevoService { @@ -45,6 +46,13 @@ public function sendEmail(BrevoEmailMessage $email, array $options = []): ?array } elseif (array_key_exists('emailFrom', $options)) { $email->from($options['emailFrom']); } + + $templateResponse = $this->http->get('/smtp/templates/'. $email->templateId); + + if (! $templateResponse->successful()) { + throw new BrevoException($templateResponse->toPsrResponse()); + } + $response = $this->http->post('/smtp/email', $email->toArray()); if (! $response->successful()) { diff --git a/src/BrevoSmsChannel.php b/src/BrevoSmsChannel.php index 9d59ec2..34793a3 100644 --- a/src/BrevoSmsChannel.php +++ b/src/BrevoSmsChannel.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\Notification; +use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException; class BrevoSmsChannel { diff --git a/src/BrevoException.php b/src/Exceptions/BrevoException.php similarity index 89% rename from src/BrevoException.php rename to src/Exceptions/BrevoException.php index fe78154..196f0ac 100644 --- a/src/BrevoException.php +++ b/src/Exceptions/BrevoException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace YieldStudio\LaravelBrevoNotifier; +namespace YieldStudio\LaravelBrevoNotifier\Exceptions; use Exception; use Psr\Http\Message\ResponseInterface; From 695722d75e03ab488c3e27de491078ba120204f0 Mon Sep 17 00:00:00 2001 From: mckenziearts Date: Fri, 16 Aug 2024 09:25:39 +0000 Subject: [PATCH 2/3] Fix styling --- src/BrevoService.php | 2 +- tests/BrevoEmailChannelTest.php | 4 ++-- tests/BrevoSmsChannelTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BrevoService.php b/src/BrevoService.php index 02c48c0..25a0348 100644 --- a/src/BrevoService.php +++ b/src/BrevoService.php @@ -47,7 +47,7 @@ public function sendEmail(BrevoEmailMessage $email, array $options = []): ?array $email->from($options['emailFrom']); } - $templateResponse = $this->http->get('/smtp/templates/'. $email->templateId); + $templateResponse = $this->http->get('/smtp/templates/' . $email->templateId); if (! $templateResponse->successful()) { throw new BrevoException($templateResponse->toPsrResponse()); diff --git a/tests/BrevoEmailChannelTest.php b/tests/BrevoEmailChannelTest.php index 5cb9d1b..9c2931c 100644 --- a/tests/BrevoEmailChannelTest.php +++ b/tests/BrevoEmailChannelTest.php @@ -12,7 +12,7 @@ $mock = $this->mock(BrevoService::class)->shouldReceive('sendEmail')->once(); $channel = new BrevoEmailChannel($mock->getMock()); - $channel->send(new User(), new class extends Notification + $channel->send(new User, new class extends Notification { public function via() { @@ -21,7 +21,7 @@ public function via() public function toBrevoEmail(User $notifiable): BrevoEmailMessage { - return new BrevoEmailMessage(); + return new BrevoEmailMessage; } }); }); diff --git a/tests/BrevoSmsChannelTest.php b/tests/BrevoSmsChannelTest.php index ab6a0a1..c3fa68a 100644 --- a/tests/BrevoSmsChannelTest.php +++ b/tests/BrevoSmsChannelTest.php @@ -12,7 +12,7 @@ it('send notification via BrevoChannel should call BrevoService sendSms method', function () { $mock = $this->mock(BrevoService::class)->shouldReceive('sendSms')->once(); $channel = new BrevoSmsChannel($mock->getMock()); - $channel->send(new User(), new class extends Notification + $channel->send(new User, new class extends Notification { public function via() { @@ -21,7 +21,7 @@ public function via() public function toBrevoSms(Model $notifiable): BrevoSmsMessage { - return new BrevoSmsMessage(); + return new BrevoSmsMessage; } }); }); From b12f6944251addcd9b3ef09f2c61cd6bf0456cf7 Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Fri, 16 Aug 2024 11:34:43 +0200 Subject: [PATCH 3/3] chore: Update tests github action --- .github/workflows/tests.yml | 24 ++++++++++++++++-------- composer.json | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8f37b30..31882ef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,21 +13,28 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.1", "8.2"] - laravel: ["^9.0", "^10.0", "^11"] - dependency-version: [ prefer-lowest, prefer-stable ] + php: [8.1, 8.2] + laravel: [9.*, 10.*, 11.*] + dependency-version: [prefer-stable] + include: + - laravel: 11.* + testbench: 9.* + - laravel: 10.* + testbench: 8.* + - laravel: 9.* + testbench: 7.* exclude: - - laravel: 11 + - laravel: 11.* php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.composer/cache/files key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} @@ -36,12 +43,13 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, exif + tools: composer:v2 coverage: none - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" --dev --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --dev --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/pest diff --git a/composer.json b/composer.json index fe5d49d..44041e3 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "require-dev": { "ciareis/bypass": "^1.0", "laravel/pint": "^1.16", - "orchestra/testbench": "^7.22|^8.1", + "orchestra/testbench": "^7.44|^8.25|^9.0", "pestphp/pest": "^2.34", "phpunit/phpunit": "^9.5|^10.5" },