-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
FrequencyTest.php
205 lines (166 loc) · 6.18 KB
/
FrequencyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
namespace Illuminate\Tests\Console\Scheduling;
use Illuminate\Console\Scheduling\Event;
use Illuminate\Console\Scheduling\EventMutex;
use Illuminate\Support\Carbon;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class FrequencyTest extends TestCase
{
/*
* @var \Illuminate\Console\Scheduling\Event
*/
protected $event;
protected function setUp(): void
{
Carbon::setTestNow();
$this->event = new Event(
m::mock(EventMutex::class),
'php foo'
);
}
public function testEveryMinute()
{
$this->assertSame('* * * * *', $this->event->getExpression());
$this->assertSame('* * * * *', $this->event->everyMinute()->getExpression());
}
public function testEveryXMinutes()
{
$this->assertSame('*/2 * * * *', $this->event->everyTwoMinutes()->getExpression());
$this->assertSame('*/3 * * * *', $this->event->everyThreeMinutes()->getExpression());
$this->assertSame('*/4 * * * *', $this->event->everyFourMinutes()->getExpression());
$this->assertSame('*/5 * * * *', $this->event->everyFiveMinutes()->getExpression());
$this->assertSame('*/10 * * * *', $this->event->everyTenMinutes()->getExpression());
$this->assertSame('*/15 * * * *', $this->event->everyFifteenMinutes()->getExpression());
$this->assertSame('0,30 * * * *', $this->event->everyThirtyMinutes()->getExpression());
}
public function testDaily()
{
$this->assertSame('0 0 * * *', $this->event->daily()->getExpression());
}
public function testDailyAt()
{
$this->assertSame('8 13 * * *', $this->event->dailyAt('13:08')->getExpression());
}
public function testTwiceDaily()
{
$this->assertSame('0 3,15 * * *', $this->event->twiceDaily(3, 15)->getExpression());
}
public function testWeekly()
{
$this->assertSame('0 0 * * 0', $this->event->weekly()->getExpression());
}
public function testWeeklyOn()
{
$this->assertSame('0 8 * * 1', $this->event->weeklyOn(1, '8:00')->getExpression());
}
public function testOverrideWithHourly()
{
$this->assertSame('0 * * * *', $this->event->everyFiveMinutes()->hourly()->getExpression());
$this->assertSame('37 * * * *', $this->event->hourlyAt(37)->getExpression());
$this->assertSame('15,30,45 * * * *', $this->event->hourlyAt([15, 30, 45])->getExpression());
}
public function testHourly()
{
$this->assertSame('0 */2 * * *', $this->event->everyTwoHours()->getExpression());
$this->assertSame('0 */3 * * *', $this->event->everyThreeHours()->getExpression());
$this->assertSame('0 */4 * * *', $this->event->everyFourHours()->getExpression());
$this->assertSame('0 */6 * * *', $this->event->everySixHours()->getExpression());
}
public function testMonthly()
{
$this->assertSame('0 0 1 * *', $this->event->monthly()->getExpression());
}
public function testMonthlyOn()
{
$this->assertSame('0 15 4 * *', $this->event->monthlyOn(4, '15:00')->getExpression());
}
public function testLastDayOfMonth()
{
Carbon::setTestNow('2020-10-10 10:10:10');
$this->assertSame('0 0 31 * *', $this->event->lastDayOfMonth()->getExpression());
}
public function testTwiceMonthly()
{
$this->assertSame('0 0 1,16 * *', $this->event->twiceMonthly(1, 16)->getExpression());
}
public function testTwiceMonthlyAtTime()
{
$this->assertSame('30 1 1,16 * *', $this->event->twiceMonthly(1, 16, '1:30')->getExpression());
}
public function testMonthlyOnWithMinutes()
{
$this->assertSame('15 15 4 * *', $this->event->monthlyOn(4, '15:15')->getExpression());
}
public function testWeekdaysDaily()
{
$this->assertSame('0 0 * * 1-5', $this->event->weekdays()->daily()->getExpression());
}
public function testWeekdaysHourly()
{
$this->assertSame('0 * * * 1-5', $this->event->weekdays()->hourly()->getExpression());
}
public function testWeekdays()
{
$this->assertSame('* * * * 1-5', $this->event->weekdays()->getExpression());
}
public function testWeekends()
{
$this->assertSame('* * * * 6,0', $this->event->weekends()->getExpression());
}
public function testSundays()
{
$this->assertSame('* * * * 0', $this->event->sundays()->getExpression());
}
public function testMondays()
{
$this->assertSame('* * * * 1', $this->event->mondays()->getExpression());
}
public function testTuesdays()
{
$this->assertSame('* * * * 2', $this->event->tuesdays()->getExpression());
}
public function testWednesdays()
{
$this->assertSame('* * * * 3', $this->event->wednesdays()->getExpression());
}
public function testThursdays()
{
$this->assertSame('* * * * 4', $this->event->thursdays()->getExpression());
}
public function testFridays()
{
$this->assertSame('* * * * 5', $this->event->fridays()->getExpression());
}
public function testSaturdays()
{
$this->assertSame('* * * * 6', $this->event->saturdays()->getExpression());
}
public function testQuarterly()
{
$this->assertSame('0 0 1 1-12/3 *', $this->event->quarterly()->getExpression());
}
public function testYearly()
{
$this->assertSame('0 0 1 1 *', $this->event->yearly()->getExpression());
}
public function testYearlyOn()
{
$this->assertSame('8 15 5 4 *', $this->event->yearlyOn(4, 5, '15:08')->getExpression());
}
public function testYearlyOnMondaysOnly()
{
$this->assertSame('1 9 * 7 1', $this->event->mondays()->yearlyOn(7, '*', '09:01')->getExpression());
}
public function testYearlyOnTuesdaysAndDayOfMonth20()
{
$this->assertSame('1 9 20 7 2', $this->event->tuesdays()->yearlyOn(7, 20, '09:01')->getExpression());
}
public function testFrequencyMacro()
{
Event::macro('everyXMinutes', function ($x) {
return $this->spliceIntoPosition(1, "*/{$x}");
});
$this->assertSame('*/6 * * * *', $this->event->everyXMinutes(6)->getExpression());
}
}