Skip to content

Commit 20cc664

Browse files
committed
Manual constraint.
1 parent 782878e commit 20cc664

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

src/Models/Concerns/ConstraintsResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Binarcode\LaravelMailator\Constraints\AfterConstraint;
77
use Binarcode\LaravelMailator\Constraints\BeforeConstraint;
88
use Binarcode\LaravelMailator\Constraints\DailyConstraint;
9+
use Binarcode\LaravelMailator\Constraints\ManualConstraint;
910
use Binarcode\LaravelMailator\Constraints\ManyConstraint;
1011
use Binarcode\LaravelMailator\Constraints\NeverConstraint;
1112
use 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,

src/Models/MailatorSchedule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

tests/Feature/Models/MailatorScheduleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)