Skip to content

Commit

Permalink
Allow multiple email addresses (#74)
Browse files Browse the repository at this point in the history
* Add possibility to use multiple email addresses

* Add test case for email list

Co-authored-by: Stefan Damjanovic <>
  • Loading branch information
stfndamjanovic committed Nov 6, 2022
1 parent fca549e commit bac1329
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -73,7 +73,7 @@ return [
'channels' => ['mail', 'slack'],

'mail' => [
'to' => 'email@example.com',
'to' => ['email@example.com'],
],

'slack' => [
Expand Down
2 changes: 1 addition & 1 deletion config/failed-job-monitor.php
Expand Up @@ -27,7 +27,7 @@
'channels' => ['mail', 'slack'],

'mail' => [
'to' => 'email@example.com',
'to' => ['email@example.com'],
],

'slack' => [
Expand Down
10 changes: 8 additions & 2 deletions src/Notifiable.php
Expand Up @@ -8,9 +8,15 @@ class Notifiable
{
use NotifiableTrait;

public function routeNotificationForMail(): string
public function routeNotificationForMail(): array
{
return config('failed-job-monitor.mail.to');
$recipients = config('failed-job-monitor.mail.to');

if (is_string($recipients)) {
return [$recipients];
}

return $recipients;
}

public function routeNotificationForSlack(): string
Expand Down
21 changes: 21 additions & 0 deletions tests/NotifiableTest.php
@@ -0,0 +1,21 @@
<?php

namespace Spatie\FailedJobMonitor\Test;

use Spatie\FailedJobMonitor\Notifiable;

class NotifiableTest extends TestCase
{
/** @test */
public function it_returns_always_list_of_emails()
{
$notifiable = new Notifiable();

$this->app['config']->set('failed-job-monitor.mail.to', 'example@gmail.com');
$this->assertEquals(['example@gmail.com'], $notifiable->routeNotificationForMail());

$recipients = ['example@gmail.com', 'example2@gmail.com'];
$this->app['config']->set('failed-job-monitor.mail.to', $recipients);
$this->assertEquals($recipients, $notifiable->routeNotificationForMail());
}
}

0 comments on commit bac1329

Please sign in to comment.