Skip to content

Commit 403a616

Browse files
authored
Sandbox mode revisions (#4)
* rename sandbox_mode to sandboxMode * update readme * change method signature * run actions on PRs to dev
1 parent defecfa commit 403a616

File tree

4 files changed

+21
-53
lines changed

4 files changed

+21
-53
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
pull_request:
88
branches:
99
- master
10+
- dev
1011

1112
jobs:
1213
test:

README.md

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -99,57 +99,22 @@ class ExampleNotification extends Notification
9999

100100
💡 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');`
101101

102-
## Sandbox Mode
102+
### Enabling Sandbox Mode
103103

104-
To enable sandbox mode you will need to
105-
106-
1. Chain on the `enableSandboxMode(true)` to the `new SendGridMessage('template_id')`
104+
To enable sandbox mode you will need to chain on the `enableSandboxMode()` to the message object.
107105

108106
Example:
109107

110108
```php
111-
<?php
112-
113-
namespace App\Notifications;
114-
115-
use Illuminate\Notifications\Notification;
116-
use NotificationChannels\SendGrid\SendGridChannel;
117-
118-
class ExampleNotification extends Notification
119-
{
120-
public function via($notifiable)
121-
{
122-
return [
123-
SendGridChannel::class,
124-
// And any other channels you want can go here...
125-
];
126-
}
127-
128-
// ...
129-
130-
public function toSendGrid($notifiable)
131-
{
132-
return (new SendGridMessage('Your SendGrid template ID'))
133-
/**
134-
* optionally set the from address.
135-
* by default this comes from config/mail.from
136-
* ->from('[email protected]', 'App name')
137-
*/
138-
/**
139-
* optionally set the recipient.
140-
* by default it's $notifiable->email:
141-
* ->to('[email protected]', 'Mr. Smith')
142-
*/
143-
144-
->enableSandboxMode(true)
145-
->payload([
146-
"template_var_1" => "template_value_1"
147-
]);
148-
}
149-
}
150-
109+
return (new SendGridMessage('Your SendGrid template ID'))
110+
->enableSandboxMode()
111+
->payload([
112+
"template_var_1" => "template_value_1"
113+
]);
151114
```
152115

116+
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).
117+
153118
## Changelog
154119

155120
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

src/SendGridMessage.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SendGridMessage
4747
*
4848
* @var bool
4949
*/
50-
public $sandbox_mode = false;
50+
public $sandboxMode = false;
5151

5252
/**
5353
* Create a new SendGrid channel instance.
@@ -117,7 +117,7 @@ public function build(): Mail
117117

118118
$email->setTemplateId($this->templateId);
119119

120-
if($this->sandbox_mode){
120+
if ($this->sandboxMode) {
121121
$email->enableSandBoxMode();
122122
}
123123

@@ -129,14 +129,16 @@ public function build(): Mail
129129
}
130130

131131
/**
132-
* Set the "sandbox_mode".
132+
* Enabling sandbox mode allows you to send a test email to
133+
* ensure that your request body is formatted correctly
134+
* without delivering the email to any of your recipients.
133135
*
134-
* @param bool $enabled
136+
* @see https://docs.sendgrid.com/for-developers/sending-email/sandbox-mode
135137
* @return $this
136138
*/
137-
public function enableSandboxMode($enabled)
139+
public function enableSandboxMode()
138140
{
139-
$this->sandbox_mode = $enabled;
141+
$this->sandboxMode = true;
140142

141143
return $this;
142144
}

tests/SendGridChannelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function toSendGrid($notifiable)
5656
$this->assertEquals($message->payload['baz'], 'foo2');
5757
$this->assertEquals($message->replyTo->getEmail(), '[email protected]');
5858
$this->assertEquals($message->replyTo->getName(), 'Reply To');
59-
$this->assertEquals($message->sandbox_mode, false);
59+
$this->assertEquals($message->sandboxMode, false);
6060

6161
// TODO: Verify that the Mail instance passed contains all the info from above
6262
$sendgrid->shouldReceive('send')->once()->andReturn($response);
@@ -77,7 +77,7 @@ public function toSendGrid($notifiable)
7777
'bar' => 'foo',
7878
'baz' => 'foo2',
7979
])
80-
->enableSandboxMode(true);
80+
->enableSandboxMode();
8181
}
8282
};
8383

@@ -103,7 +103,7 @@ public function toSendGrid($notifiable)
103103
$this->assertEquals($message->payload['baz'], 'foo2');
104104
$this->assertEquals($message->replyTo->getEmail(), '[email protected]');
105105
$this->assertEquals($message->replyTo->getName(), 'Reply To');
106-
$this->assertEquals($message->sandbox_mode, true);
106+
$this->assertEquals($message->sandboxMode, true);
107107

108108
// TODO: Verify that the Mail instance passed contains all the info from above
109109
$sendgrid->shouldReceive('send')->once()->andReturn($response);

0 commit comments

Comments
 (0)