|
6 | 6 | use Spatie\Backup\Events\BackupHasFailed;
|
7 | 7 | use Spatie\Backup\Notifications\Notifiable;
|
8 | 8 | use Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification;
|
| 9 | +use Spatie\Backup\Exceptions\InvalidConfig; |
| 10 | +use Spatie\Backup\Config\NotificationMailConfig; |
9 | 11 |
|
10 | 12 | beforeEach(function () {
|
11 | 13 | Notification::fake();
|
|
50 | 52 | Notification::assertSentTimes(BackupHasFailedNotification::class, 1);
|
51 | 53 | });
|
52 | 54 |
|
| 55 | +it('will accept a single email address', function () { |
| 56 | + $data = [ |
| 57 | + |
| 58 | + 'from' => [ |
| 59 | + |
| 60 | + 'name' => 'Backup', |
| 61 | + ], |
| 62 | + ]; |
| 63 | + |
| 64 | + $config = NotificationMailConfig::fromArray($data); |
| 65 | + |
| 66 | + expect( $config-> to)-> toBe([ '[email protected]']); |
| 67 | +}); |
| 68 | + |
| 69 | +it('will accept multiple email addresses', function () { |
| 70 | + $data = [ |
| 71 | + |
| 72 | + 'from' => [ |
| 73 | + |
| 74 | + 'name' => 'Backup', |
| 75 | + ], |
| 76 | + ]; |
| 77 | + |
| 78 | + $config = NotificationMailConfig::fromArray($data); |
| 79 | + |
| 80 | + expect( $config-> to)-> toBe([ '[email protected]', '[email protected]']); |
| 81 | +}); |
| 82 | + |
| 83 | +it('will throw an exception for invalid email', function () { |
| 84 | + $data = [ |
| 85 | + 'to' => 'invalid-email', |
| 86 | + 'from' => [ |
| 87 | + |
| 88 | + 'name' => 'Backup', |
| 89 | + ], |
| 90 | + ]; |
| 91 | + |
| 92 | + expect(fn() => NotificationMailConfig::fromArray($data))->toThrow(InvalidConfig::class); |
| 93 | +}); |
| 94 | + |
| 95 | +it('will throw an exception for invalid email in array', function () { |
| 96 | + $data = [ |
| 97 | + 'to' => [ '[email protected]', 'invalid-email'], |
| 98 | + 'from' => [ |
| 99 | + |
| 100 | + 'name' => 'Backup', |
| 101 | + ], |
| 102 | + ]; |
| 103 | + |
| 104 | + expect(fn() => NotificationMailConfig::fromArray($data))->toThrow(InvalidConfig::class); |
| 105 | +}); |
| 106 | + |
53 | 107 | function fireBackupHasFailedEvent(): void
|
54 | 108 | {
|
55 | 109 | $exception = new Exception('Dummy exception');
|
|
0 commit comments