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 ManualConstraint implements SendScheduleConstraint
9+ {
10+ public function canSend (MailatorSchedule $ schedule , Collection $ logs ): bool
11+ {
12+ return $ schedule ->isManual ()
13+ ? false
14+ : true ;
15+ }
16+ }
Original file line number Diff line number Diff line change 66use Binarcode \LaravelMailator \Constraints \AfterConstraint ;
77use Binarcode \LaravelMailator \Constraints \BeforeConstraint ;
88use Binarcode \LaravelMailator \Constraints \DailyConstraint ;
9+ use Binarcode \LaravelMailator \Constraints \ManualConstraint ;
910use Binarcode \LaravelMailator \Constraints \ManyConstraint ;
1011use Binarcode \LaravelMailator \Constraints \NeverConstraint ;
1112use Binarcode \LaravelMailator \Constraints \OnceConstraint ;
@@ -26,6 +27,7 @@ public function configurationsPasses(): bool
2627 BeforeConstraint::class,
2728 AfterConstraint::class,
2829 NeverConstraint::class,
30+ ManualConstraint::class,
2931 OnceConstraint::class,
3032 ManyConstraint::class,
3133 DailyConstraint::class,
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ public function getTable()
7272 const FREQUENCY_OPTIONS_DAILY = 'daily ' ;
7373 const FREQUENCY_OPTIONS_WEEKLY = 'weekly ' ;
7474 const FREQUENCY_OPTIONS_NEVER = 'never ' ;
75+ const FREQUENCY_OPTIONS_MANUAL = 'manual ' ;
7576
7677 protected $ fillable = [
7778 'action ' ,
@@ -120,6 +121,13 @@ public function once(): self
120121 return $ this ;
121122 }
122123
124+ public function manual (): self
125+ {
126+ $ this ->frequency_option = static ::FREQUENCY_OPTIONS_MANUAL ;
127+
128+ return $ this ;
129+ }
130+
123131 public function never (): self
124132 {
125133 $ this ->frequency_option = static ::FREQUENCY_OPTIONS_NEVER ;
@@ -214,6 +222,11 @@ public function isNever(): bool
214222 return $ this ->frequency_option === static ::FREQUENCY_OPTIONS_NEVER ;
215223 }
216224
225+ public function isManual (): bool
226+ {
227+ return $ this ->frequency_option === static ::FREQUENCY_OPTIONS_MANUAL ;
228+ }
229+
217230 public function isMany (): bool
218231 {
219232 return $ this ->frequency_option === static ::FREQUENCY_OPTIONS_MANY ;
Original file line number Diff line number Diff line change @@ -94,6 +94,26 @@ public function test_sending_email_never_automatically()
9494 Mail::assertSent (InvoiceReminderMailable::class, 0 );
9595 }
9696
97+ public function test_sending_email_manual_dont_send_automatically ()
98+ {
99+ Mail::fake ();
100+ Mail::assertNothingSent ();
101+
102+ MailatorSchedule::init ('Invoice reminder. ' )
103+ ->manual ()
104+ ->recipients ([
105+ 106+ ])
107+ ->mailable (
108+ (
new InvoiceReminderMailable ())->
to (
'[email protected] ' )
109+ )
110+ ->days (1 )
111+ ->save ();
112+
113+ MailatorSchedule::run ();
114+ Mail::assertSent (InvoiceReminderMailable::class, 0 );
115+ }
116+
97117 public function test_can_send_serialized_constrained ()
98118 {
99119 Mail::fake ();
You can’t perform that action at this time.
0 commit comments