ILIAS  release_8 Revision v8.24
CronJobEntityTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
27class CronJobEntityTest extends TestCase
28{
36 private function getEntity(
37 ilCronJob $job_instance = null,
38 int $schedule_type = ilCronJob::SCHEDULE_TYPE_IN_MINUTES,
39 int $schedule_value = 5,
40 bool $is_plugin = false
42 $job_instance ??= $this->createMock(ilCronJob::class);
43
44 return new ilCronJobEntity($job_instance, [
45 'job_id' => 'phpunit',
46 'component' => 'phpunit',
47 'schedule_type' => $schedule_type,
48 'schedule_value' => $schedule_value,
49 'job_status' => 1,
50 'job_status_user_id' => 6,
51 'job_status_type' => 1,
52 'job_status_ts' => time(),
53 'job_result_status' => ilCronJobResult::STATUS_OK,
54 'job_result_user_id' => 6,
55 'job_result_code' => ilCronJobResult::CODE_NO_RESULT,
56 'job_result_message' => 'msg',
57 'job_result_type' => 1,
58 'job_result_ts' => time(),
59 'class' => 'Job',
60 'path' => '/',
61 'running_ts' => time(),
62 'job_result_dur' => time(),
63 'alive_ts' => time(),
64 ], $is_plugin);
65 }
66
68 {
69 $entities = new ilCronJobEntities($this->getEntity(), $this->getEntity());
70
71 $this->assertCount(2, $entities->toArray());
72
73 return $entities;
74 }
75
82 {
83 $entities->add($this->getEntity());
84
85 $this->assertCount(3, $entities->toArray());
86
87 return $entities;
88 }
89
95 {
96 $this->assertCount(0, $entities->filter(static function (ilCronJobEntity $entity): bool {
97 return $entity->getJobId() !== 'phpunit';
98 }));
99
100 $this->assertCount(1, $entities->slice(1, 1));
101 }
102
104 {
105 $job_instance = $this->createMock(ilCronJob::class);
106 $job_instance->method('hasFlexibleSchedule')->willReturn(true);
107
108 $entity = $this->getEntity($job_instance);
109 $this->assertSame(ilCronJob::SCHEDULE_TYPE_IN_MINUTES, $entity->getEffectiveScheduleType());
110 $this->assertSame(5, $entity->getEffectiveScheduleValue());
111
112 $another_job_instance = $this->createMock(ilCronJob::class);
113 $another_job_instance->method('hasFlexibleSchedule')->willReturn(false);
114 $another_job_instance->method('getDefaultScheduleType')->willReturn(ilCronJob::SCHEDULE_TYPE_IN_HOURS);
115 $another_job_instance->method('getDefaultScheduleValue')->willReturn(5);
116
117 $another_entity = $this->getEntity($another_job_instance, ilCronJob::SCHEDULE_TYPE_DAILY);
118 $this->assertSame(ilCronJob::SCHEDULE_TYPE_IN_HOURS, $another_entity->getEffectiveScheduleType());
119 $this->assertSame(5, $another_entity->getEffectiveScheduleValue());
120
121 $yet_another_job_instance = $this->createMock(ilCronJob::class);
122 $yet_another_job_instance->method('hasFlexibleSchedule')->willReturn(true);
123 $yet_another_job_instance->method('getDefaultScheduleType')->willReturn(ilCronJob::SCHEDULE_TYPE_IN_HOURS);
124 $yet_another_job_instance->method('getDefaultScheduleValue')->willReturn(5);
125
126 $yet_another_entity = $this->getEntity($yet_another_job_instance, 0);
127 $this->assertSame(ilCronJob::SCHEDULE_TYPE_IN_HOURS, $yet_another_entity->getEffectiveScheduleType());
128 $this->assertSame(5, $yet_another_entity->getEffectiveScheduleValue());
129 }
130}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Class CronJobEntityTest.
testCollectionCanBeChanged(ilCronJobEntities $entities)
getEntity(ilCronJob $job_instance=null, int $schedule_type=ilCronJob::SCHEDULE_TYPE_IN_MINUTES, int $schedule_value=5, bool $is_plugin=false)
testCollectionCanBeFilteredAndSliced(ilCronJobEntities $entities)
filter(callable $callable)
Returns all the elements of this collection that satisfy the predicate $callable.
slice(int $offset, ?int $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection.
add(ilCronJobEntity $job)
const SCHEDULE_TYPE_IN_HOURS
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_IN_MINUTES
@depracated This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9