-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.x] Add support for both single email string and array of email str…
…ings (#1810) * Add support for both single email string and array of email strings * Add tests to handle single and multiple email addresses
- Loading branch information
Showing
2 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
use Spatie\Backup\Events\BackupHasFailed; | ||
use Spatie\Backup\Notifications\Notifiable; | ||
use Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification; | ||
use Spatie\Backup\Exceptions\InvalidConfig; | ||
use Spatie\Backup\Config\NotificationMailConfig; | ||
|
||
beforeEach(function () { | ||
Notification::fake(); | ||
|
@@ -50,6 +52,58 @@ | |
Notification::assertSentTimes(BackupHasFailedNotification::class, 1); | ||
}); | ||
|
||
it('will accept a single email address', function () { | ||
$data = [ | ||
'to' => '[email protected]', | ||
'from' => [ | ||
'address' => '[email protected]', | ||
'name' => 'Backup', | ||
], | ||
]; | ||
|
||
$config = NotificationMailConfig::fromArray($data); | ||
|
||
expect($config->to)->toBe(['[email protected]']); | ||
}); | ||
|
||
it('will accept multiple email addresses', function () { | ||
$data = [ | ||
'to' => ['[email protected]', '[email protected]'], | ||
'from' => [ | ||
'address' => '[email protected]', | ||
'name' => 'Backup', | ||
], | ||
]; | ||
|
||
$config = NotificationMailConfig::fromArray($data); | ||
|
||
expect($config->to)->toBe(['[email protected]', '[email protected]']); | ||
}); | ||
|
||
it('will throw an exception for invalid email', function () { | ||
$data = [ | ||
'to' => 'invalid-email', | ||
'from' => [ | ||
'address' => '[email protected]', | ||
'name' => 'Backup', | ||
], | ||
]; | ||
|
||
expect(fn() => NotificationMailConfig::fromArray($data))->toThrow(InvalidConfig::class); | ||
}); | ||
|
||
it('will throw an exception for invalid email in array', function () { | ||
$data = [ | ||
'to' => ['[email protected]', 'invalid-email'], | ||
'from' => [ | ||
'address' => '[email protected]', | ||
'name' => 'Backup', | ||
], | ||
]; | ||
|
||
expect(fn() => NotificationMailConfig::fromArray($data))->toThrow(InvalidConfig::class); | ||
}); | ||
|
||
function fireBackupHasFailedEvent(): void | ||
{ | ||
$exception = new Exception('Dummy exception'); | ||
|