diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ca1c7a..ea0d9f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - master + - dev jobs: test: diff --git a/README.md b/README.md index 342f4df..4c534a5 100644 --- a/README.md +++ b/README.md @@ -99,57 +99,22 @@ class ExampleNotification extends Notification 💡 Unless you set it explicitly, the **From** address will be set to `config('mail.from.address')` and the **To** value will be what returns from `$notifiable->routeNotificationFor('mail');` -## Sandbox Mode +### Enabling Sandbox Mode -To enable sandbox mode you will need to - -1. Chain on the `enableSandboxMode(true)` to the `new SendGridMessage('template_id')` +To enable sandbox mode you will need to chain on the `enableSandboxMode()` to the message object. Example: ```php -from('no-reply@test.com', 'App name') - */ - /** - * optionally set the recipient. - * by default it's $notifiable->email: - * ->to('hello@example.com', 'Mr. Smith') - */ - - ->enableSandboxMode(true) - ->payload([ - "template_var_1" => "template_value_1" - ]); - } -} - +return (new SendGridMessage('Your SendGrid template ID')) + ->enableSandboxMode() + ->payload([ + "template_var_1" => "template_value_1" + ]); ``` +When making a request with sandbox mode enabled, Sendgrid will validate the form, type, and shape of your request. No email will be sent. You can read more about the sandbox mode [here](https://docs.sendgrid.com/for-developers/sending-email/sandbox-mode). + ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. diff --git a/src/SendGridMessage.php b/src/SendGridMessage.php index 6ee2e45..188e013 100644 --- a/src/SendGridMessage.php +++ b/src/SendGridMessage.php @@ -47,7 +47,7 @@ class SendGridMessage * * @var bool */ - public $sandbox_mode = false; + public $sandboxMode = false; /** * Create a new SendGrid channel instance. @@ -117,7 +117,7 @@ public function build(): Mail $email->setTemplateId($this->templateId); - if($this->sandbox_mode){ + if ($this->sandboxMode) { $email->enableSandBoxMode(); } @@ -129,14 +129,16 @@ public function build(): Mail } /** - * Set the "sandbox_mode". + * Enabling sandbox mode allows you to send a test email to + * ensure that your request body is formatted correctly + * without delivering the email to any of your recipients. * - * @param bool $enabled + * @see https://docs.sendgrid.com/for-developers/sending-email/sandbox-mode * @return $this */ - public function enableSandboxMode($enabled) + public function enableSandboxMode() { - $this->sandbox_mode = $enabled; + $this->sandboxMode = true; return $this; } diff --git a/tests/SendGridChannelTest.php b/tests/SendGridChannelTest.php index e3dd906..2314652 100644 --- a/tests/SendGridChannelTest.php +++ b/tests/SendGridChannelTest.php @@ -56,7 +56,7 @@ public function toSendGrid($notifiable) $this->assertEquals($message->payload['baz'], 'foo2'); $this->assertEquals($message->replyTo->getEmail(), 'replyto@example.com'); $this->assertEquals($message->replyTo->getName(), 'Reply To'); - $this->assertEquals($message->sandbox_mode, false); + $this->assertEquals($message->sandboxMode, false); // TODO: Verify that the Mail instance passed contains all the info from above $sendgrid->shouldReceive('send')->once()->andReturn($response); @@ -77,7 +77,7 @@ public function toSendGrid($notifiable) 'bar' => 'foo', 'baz' => 'foo2', ]) - ->enableSandboxMode(true); + ->enableSandboxMode(); } }; @@ -103,7 +103,7 @@ public function toSendGrid($notifiable) $this->assertEquals($message->payload['baz'], 'foo2'); $this->assertEquals($message->replyTo->getEmail(), 'replyto@example.com'); $this->assertEquals($message->replyTo->getName(), 'Reply To'); - $this->assertEquals($message->sandbox_mode, true); + $this->assertEquals($message->sandboxMode, true); // TODO: Verify that the Mail instance passed contains all the info from above $sendgrid->shouldReceive('send')->once()->andReturn($response);