19 declare(strict_types=1);
34 bool $has_flexible_schedule,
35 int $default_schedule_type,
36 ?
int $default_schedule_value,
40 $job_instance =
new class ($has_flexible_schedule, $default_schedule_type, $default_schedule_value, $schedule_type, $schedule_value) extends
ilCronJob {
41 private bool $has_flexible_schedule;
42 private int $default_schedule_type;
43 private ?
int $default_schedule_value;
46 bool $has_flexible_schedule,
47 int $default_schedule_type,
48 ?
int $default_schedule_value,
52 $this->has_flexible_schedule = $has_flexible_schedule;
53 $this->schedule_type = $schedule_type;
54 $this->schedule_value = $schedule_value;
55 $this->default_schedule_type = $default_schedule_type;
56 $this->default_schedule_value = $default_schedule_value;
59 public function getId():
string 64 public function getTitle():
string 69 public function getDescription():
string 74 public function hasAutoActivation():
bool 79 public function hasFlexibleSchedule():
bool 81 return $this->has_flexible_schedule;
84 public function getDefaultScheduleType():
int 86 return $this->default_schedule_type;
89 public function getDefaultScheduleValue(): ?
int 91 return $this->default_schedule_value;
104 return $job_instance;
112 $offset = (((
int) $this->now->format(
'n')) - 1) % 3;
113 $this->this_quarter_start = $this->now->modify(
"first day of -$offset month midnight");
116 'Manual Run is Always Due' => [
124 'Job Without Any Run is Always Due' => [
125 $this->
getJob(
true, ilCronJob::SCHEDULE_TYPE_DAILY, null, ilCronJob::SCHEDULE_TYPE_DAILY, null),
132 'Daily Schedule / Did not run Today' => [
133 $this->
getJob(
true, ilCronJob::SCHEDULE_TYPE_DAILY, null, ilCronJob::SCHEDULE_TYPE_DAILY, null),
135 $this->now->modify(
'-1 day'),
140 'Daily Schedule / Did run Today' => [
141 $this->
getJob(
true, ilCronJob::SCHEDULE_TYPE_DAILY, null, ilCronJob::SCHEDULE_TYPE_DAILY, null),
148 'Weekly Schedule / Did not run this Week' => [
151 $this->now->modify(
'-1 week'),
156 'Weekly Schedule / Did run this Week' => [
159 $this->now->modify(
'monday this week'),
164 'Monthly Schedule / Did not run this Month' => [
167 $this->now->modify(
'last day of last month'),
172 'Monthly Schedule / Did run this Month' => [
175 $this->now->modify(
'first day of this month'),
180 'Yearly Schedule / Did not run this Year' => [
183 $this->now->modify(
'-1 year'),
188 'Yearly Schedule / Did run this Year' => [
191 $this->now->modify(
'first day of January this year'),
196 'Quarterly Schedule / Did not run this Quarter' => [
199 $this->this_quarter_start->modify(
'-1 seconds'),
204 'Quarterly Schedule / Did run this Quarter' => [
207 $this->this_quarter_start->modify(
'+30 seconds'),
212 'Minutely Schedule / Did not run this Minute' => [
215 $this->now->modify(
'-1 minute'),
220 'Minutely Schedule / Did run this Minute' => [
223 $this->now->modify(
'-30 seconds'),
228 'Hourly Schedule / Did not run this Hour' => [
231 $this->now->modify(
'-7 hours'),
236 'Hourly Schedule / Did run this Hour' => [
239 $this->now->modify(
'-7 hours +30 seconds'),
244 'Every 5 Days Schedule / Did not run for 5 Days' => [
247 $this->now->modify(
'-5 days'),
252 'Every 5 Days Schedule / Did run withing the last 5 Days' => [
255 $this->now->modify(
'-4 days'),
260 'Invalid Schedule Type' => [
261 $this->
getJob(
true, PHP_INT_MAX, 5, PHP_INT_MAX, 5),
279 ?
int $schedule_value,
284 $job_instance->
isDue($last_run_datetime, $schedule_type, $schedule_value, $is_manual_run),
285 'Last run: ' . ($last_run_datetime ? $last_run_datetime->format(DATE_ATOM) :
'never')
291 yield
'Different Week' => [
296 return $this->now->modify(
'-1 week');
301 yield
'Same Week and Year, but different Month: December (now) and January (Last run)' => [
311 yield
'Same Week and Year and same Month: January' => [
316 return $this->now->modify(
'-1 day');
321 yield
'Same Week (52nd), but Year Difference > 1' => [
326 return $this->now->modify(
'tuesday this week')->modify(
'-1 year');
331 yield
'Same Week (52nd) in different Years, but Turn of the Year' => [
336 return $this->now->modify(
'monday this week');
341 yield
'Same Week (52nd) in different Years, but not Turn of the Year' => [
358 callable $last_run_datetime_provider,
361 $last_run_datetime = $last_run_datetime_provider();
365 $job_instance->
isDue(
371 'Last run: ' . $last_run_datetime->format(DATE_ATOM)
const SCHEDULE_TYPE_IN_MINUTES
This will be replaced with an ENUM in ILIAS 9
testWeeklySchedules(ilCronJob $job_instance, callable $last_run_datetime_provider, bool $should_be_due)
weeklyScheduleProvider
const SCHEDULE_TYPE_MONTHLY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_WEEKLY
This will be replaced with an ENUM in ILIAS 9
DateTimeImmutable $this_quarter_start
const SCHEDULE_TYPE_IN_DAYS
This will be replaced with an ENUM in ILIAS 9
Class CronJobScheduleTest.
const SCHEDULE_TYPE_YEARLY
This will be replaced with an ENUM in ILIAS 9
getJob(bool $has_flexible_schedule, int $default_schedule_type, ?int $default_schedule_value, int $schedule_type, ?int $schedule_value)
__construct(Container $dic, ilPlugin $plugin)
const SCHEDULE_TYPE_DAILY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_QUARTERLY
This will be replaced with an ENUM in ILIAS 9
getScheduleValue()
Get current schedule value (if flexible)
const SCHEDULE_TYPE_IN_HOURS
This will be replaced with an ENUM in ILIAS 9
testSchedule(ilCronJob $job_instance, bool $is_manual_run, ?DateTimeImmutable $last_run_datetime, int $schedule_type, ?int $schedule_value, bool $should_be_due)
jobProvider
getScheduleType()
Get current schedule type (if flexible)
isDue(?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)