File tree Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Binarcode \LaravelMailator \Constraints ;
4+
5+ use Binarcode \LaravelMailator \Models \MailatorSchedule ;
6+ use Illuminate \Support \Collection ;
7+
8+ class NeverConstraint implements SendScheduleConstraint
9+ {
10+ public function canSend (MailatorSchedule $ schedule , Collection $ logs ): bool
11+ {
12+ return $ schedule ->isNever ()
13+ ? false
14+ : true ;
15+ }
16+ }
Original file line number Diff line number Diff line change 77use Binarcode \LaravelMailator \Constraints \BeforeConstraint ;
88use Binarcode \LaravelMailator \Constraints \DailyConstraint ;
99use Binarcode \LaravelMailator \Constraints \ManyConstraint ;
10+ use Binarcode \LaravelMailator \Constraints \NeverConstraint ;
1011use Binarcode \LaravelMailator \Constraints \OnceConstraint ;
1112use Binarcode \LaravelMailator \Constraints \SendScheduleConstraint ;
1213use Binarcode \LaravelMailator \Constraints \WeeklyConstraint ;
@@ -24,6 +25,7 @@ public function configurationsPasses(): bool
2425 return collect ([
2526 BeforeConstraint::class,
2627 AfterConstraint::class,
28+ NeverConstraint::class,
2729 OnceConstraint::class,
2830 ManyConstraint::class,
2931 DailyConstraint::class,
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ public function getTable()
7171 const FREQUENCY_OPTIONS_HOURLY = 'hourly ' ;
7272 const FREQUENCY_OPTIONS_DAILY = 'daily ' ;
7373 const FREQUENCY_OPTIONS_WEEKLY = 'weekly ' ;
74+ const FREQUENCY_OPTIONS_NEVER = 'never ' ;
7475
7576 protected $ fillable = [
7677 'action ' ,
@@ -119,6 +120,13 @@ public function once(): self
119120 return $ this ;
120121 }
121122
123+ public function never (): self
124+ {
125+ $ this ->frequency_option = static ::FREQUENCY_OPTIONS_NEVER ;
126+
127+ return $ this ;
128+ }
129+
122130 public function many (): self
123131 {
124132 $ this ->frequency_option = static ::FREQUENCY_OPTIONS_MANY ;
@@ -201,6 +209,11 @@ public function isOnce(): bool
201209 return $ this ->frequency_option === static ::FREQUENCY_OPTIONS_ONCE ;
202210 }
203211
212+ public function isNever (): bool
213+ {
214+ return $ this ->frequency_option === static ::FREQUENCY_OPTIONS_NEVER ;
215+ }
216+
204217 public function isMany (): bool
205218 {
206219 return $ this ->frequency_option === static ::FREQUENCY_OPTIONS_MANY ;
Original file line number Diff line number Diff line change @@ -74,6 +74,26 @@ public function test_sending_email_only_once()
7474 });
7575 }
7676
77+ public function test_sending_email_never_automatically ()
78+ {
79+ Mail::fake ();
80+ Mail::assertNothingSent ();
81+
82+ MailatorSchedule::init ('Invoice reminder. ' )
83+ ->never ()
84+ ->recipients ([
85+ 86+ ])
87+ ->mailable (
88+ (
new InvoiceReminderMailable ())->
to (
'[email protected] ' )
89+ )
90+ ->days (1 )
91+ ->save ();
92+
93+ MailatorSchedule::run ();
94+ Mail::assertSent (InvoiceReminderMailable::class, 0 );
95+ }
96+
7797 public function test_can_send_serialized_constrained ()
7898 {
7999 Mail::fake ();
You can’t perform that action at this time.
0 commit comments