Skip to content

Commit 782878e

Browse files
committed
Never constraint.
1 parent b83b4d7 commit 782878e

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 NeverConstraint implements SendScheduleConstraint
9+
{
10+
public function canSend(MailatorSchedule $schedule, Collection $logs): bool
11+
{
12+
return $schedule->isNever()
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
@@ -7,6 +7,7 @@
77
use Binarcode\LaravelMailator\Constraints\BeforeConstraint;
88
use Binarcode\LaravelMailator\Constraints\DailyConstraint;
99
use Binarcode\LaravelMailator\Constraints\ManyConstraint;
10+
use Binarcode\LaravelMailator\Constraints\NeverConstraint;
1011
use Binarcode\LaravelMailator\Constraints\OnceConstraint;
1112
use Binarcode\LaravelMailator\Constraints\SendScheduleConstraint;
1213
use 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,

src/Models/MailatorSchedule.php

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

tests/Feature/Models/MailatorScheduleTest.php

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

0 commit comments

Comments
 (0)