Skip to content

Commit

Permalink
Recipients spread.
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryk committed Jun 9, 2021
1 parent d7ed07e commit 962846d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Models/MailatorSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,13 @@ public function constraint(SendScheduleConstraint $constraint): self
return $this;
}

public function recipients(array $recipients): self
public function recipients(...$recipients): self
{
$this->recipients = collect($recipients)
$this->recipients = array_merge(collect($recipients)
->flatten()
->filter(fn ($email) => $this->ensureValidEmail($email))
->toArray();
->unique()
->toArray(), $this->recipients ?? []);

return $this;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/Models/MailatorScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,24 @@ public function test_can_handle_custom_action()

MailatorSchedule::run();
}

public function test_recipients_merges()
{
Mail::fake();

$scheduler = MailatorSchedule::init('Invoice reminder.')
->recipients(
$mail = '[email protected]',
);

self::assertSame([$mail], $scheduler->recipients);

$scheduler->recipients([$mail2 = '[email protected]']);

self::assertSame([$mail2, $mail], $scheduler->recipients);

$scheduler->recipients($mail3 = '[email protected]');

self::assertSame([$mail3, $mail2, $mail], $scheduler->recipients);
}
}

0 comments on commit 962846d

Please sign in to comment.