18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
41 protected function setUp()
43 $this->timezoneBackup = date_default_timezone_get();
44 date_default_timezone_set(
'UTC');
49 date_default_timezone_set($this->timezoneBackup);
59 $this->assertSame([
'2,3',
'*',
'*',
'*',
'*'], $instance->getCronCommandSections());
67 $this->expectException(\InvalidArgumentException::class);
68 $this->expectExceptionCode(1291470170);
69 new CronCommand(
'61 * * * *');
77 $instance =
new CronCommand(
'* * * * *');
78 $currentTime = time();
79 $expectedTime = $currentTime - ($currentTime % 60) + 60;
80 $this->assertSame($expectedTime, $instance->getTimestamp());
88 $instance =
new CronCommand(
'* * * * *', self::TIMESTAMP);
89 $this->assertSame(self::TIMESTAMP + 60, $instance->getTimestamp());
97 $instance =
new CronCommand(
'* * * * *', self::TIMESTAMP + 1);
98 $this->assertSame(self::TIMESTAMP + 60, $instance->getTimestamp());
110 self::TIMESTAMP + 60,
111 self::TIMESTAMP + 120
113 'once an hour at 1' => [
116 self::TIMESTAMP + 60,
117 self::TIMESTAMP + 60 + 60 * 60
119 'once an hour at 0' => [
122 self::TIMESTAMP + 60 * 60,
123 self::TIMESTAMP + 60 * 60 + 60 * 60
125 'once a day at 1:00' => [
128 self::TIMESTAMP + 60 * 60,
129 self::TIMESTAMP + 60 * 60 + 60 * 60 * 24
131 'once a day at 0:00' => [
134 self::TIMESTAMP + 60 * 60 * 24,
135 self::TIMESTAMP + 60 * 60 * 24 * 2
140 self::TIMESTAMP + 60 * 60 * 24 * 3,
141 self::TIMESTAMP + 60 * 60 * 24 * 3 + 60 * 60 * 24 * 31
143 'once every Saturday' => [
146 self::TIMESTAMP + 60 * 60 * 24,
147 self::TIMESTAMP + 60 * 60 * 24 + 60 * 60 * 24 * 7
149 'once every day in February' => [
152 self::TIMESTAMP + 60 * 60 * 24 * 31,
153 self::TIMESTAMP + 60 * 60 * 24 * 31 + 60 * 60 * 24
155 'day of week and day of month restricted, next match in day of month field' => [
158 self::TIMESTAMP + 60 * 60 * 24,
159 self::TIMESTAMP + 60 * 60 * 24 + 60 * 60 * 24
161 'day of week and day of month restricted, next match in day of week field' => [
164 self::TIMESTAMP + 60 * 60 * 24,
165 self::TIMESTAMP + 60 * 60 * 24 + 60 * 60 * 24
167 'list of minutes' => [
170 self::TIMESTAMP + 120,
171 self::TIMESTAMP + 240
176 self::TIMESTAMP + 60 * 60 * 2,
177 self::TIMESTAMP + 60 * 60 * 4
188 'every first day of month' => [
194 'once every February' => [
200 'once every Friday February' => [
206 'first day in February and every Friday' => [
212 '29th February leap year' => [
218 'list of days in month' => [
230 'list of days of weeks' => [
248 $instance =
new CronCommand($cronCommand, $startTimestamp);
249 $instance->calculateNextValue();
250 $this->assertSame($expectedTimestamp, $instance->getTimestamp());
262 $instance =
new CronCommand($cronCommand, $startTimestamp);
263 $instance->calculateNextValue();
264 $this->assertSame(strtotime($expectedTimestamp), $instance->getTimestamp());
277 $instance =
new CronCommand($cronCommand, $firstTimestamp);
278 $instance->calculateNextValue();
279 $this->assertSame($secondTimestamp, $instance->getTimestamp());
292 $instance =
new CronCommand($cronCommand, strtotime($firstTimestamp));
293 $instance->calculateNextValue();
294 $this->assertSame(strtotime($secondTimestamp), $instance->getTimestamp());
302 $backupTimezone = date_default_timezone_get();
303 date_default_timezone_set(
'Europe/Berlin');
304 $instance =
new CronCommand(
'* 3 28 mar *', self::TIMESTAMP);
305 $instance->calculateNextValue();
306 date_default_timezone_set($backupTimezone);
307 $this->assertSame(1269741600, $instance->getTimestamp());
315 $this->expectException(\RuntimeException::class);
316 $this->expectExceptionCode(1291501280);
317 $instance =
new CronCommand(
'* * 31 apr *', self::TIMESTAMP);
318 $instance->calculateNextValue();
326 $instance =
new CronCommand(
'* * * * *');
327 $this->assertInternalType(\PHPUnit\Framework\Constraint\IsType::TYPE_INT, $instance->getTimestamp());
335 $instance =
new CronCommand(
'* * * * *');
336 $this->assertInternalType(\PHPUnit\Framework\Constraint\IsType::TYPE_ARRAY, $instance->getCronCommandSections());