ILIAS  release_8 Revision v8.24
CronJobEntityTest Class Reference

Class CronJobEntityTest. More...

+ Inheritance diagram for CronJobEntityTest:
+ Collaboration diagram for CronJobEntityTest:

Public Member Functions

 testEntityCollectionCanBeCreatedWithItems ()
 
 testCollectionCanBeChanged (ilCronJobEntities $entities)
 
 testCollectionCanBeFilteredAndSliced (ilCronJobEntities $entities)
 
 testEffectiveScheduleCanBeDetermined ()
 

Private Member Functions

 getEntity (ilCronJob $job_instance=null, int $schedule_type=ilCronJob::SCHEDULE_TYPE_IN_MINUTES, int $schedule_value=5, bool $is_plugin=false)
 

Detailed Description

Class CronJobEntityTest.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 27 of file CronJobEntityTest.php.

Member Function Documentation

◆ getEntity()

CronJobEntityTest::getEntity ( ilCronJob  $job_instance = null,
int  $schedule_type = ilCronJob::SCHEDULE_TYPE_IN_MINUTES,
int  $schedule_value = 5,
bool  $is_plugin = false 
)
private
Parameters
ilCronJob | null$job_instance
int$schedule_type
int$schedule_value
bool$is_plugin
Returns
ilCronJobEntity

Definition at line 36 of file CronJobEntityTest.php.

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 }

◆ testCollectionCanBeChanged()

CronJobEntityTest::testCollectionCanBeChanged ( ilCronJobEntities  $entities)
Parameters
ilCronJobEntities$entities
Returns
ilCronJobEntities @depends testEntityCollectionCanBeCreatedWithItems

Definition at line 81 of file CronJobEntityTest.php.

82 {
83 $entities->add($this->getEntity());
84
85 $this->assertCount(3, $entities->toArray());
86
87 return $entities;
88 }
getEntity(ilCronJob $job_instance=null, int $schedule_type=ilCronJob::SCHEDULE_TYPE_IN_MINUTES, int $schedule_value=5, bool $is_plugin=false)
add(ilCronJobEntity $job)

References ilCronJobEntities\add(), and ilCronJobEntities\toArray().

+ Here is the call graph for this function:

◆ testCollectionCanBeFilteredAndSliced()

CronJobEntityTest::testCollectionCanBeFilteredAndSliced ( ilCronJobEntities  $entities)
Parameters
ilCronJobEntities$entities@depends testCollectionCanBeChanged

Definition at line 94 of file CronJobEntityTest.php.

94 : void
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 }
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
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.

References ilCronJobEntities\filter(), function, ilCronJobEntity\getJobId(), and ilCronJobEntities\slice().

+ Here is the call graph for this function:

◆ testEffectiveScheduleCanBeDetermined()

CronJobEntityTest::testEffectiveScheduleCanBeDetermined ( )

Definition at line 103 of file CronJobEntityTest.php.

103 : void
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 }
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

References ilCronJob\SCHEDULE_TYPE_DAILY, ilCronJob\SCHEDULE_TYPE_IN_HOURS, and ilCronJob\SCHEDULE_TYPE_IN_MINUTES.

◆ testEntityCollectionCanBeCreatedWithItems()

CronJobEntityTest::testEntityCollectionCanBeCreatedWithItems ( )

Definition at line 67 of file CronJobEntityTest.php.

68 {
69 $entities = new ilCronJobEntities($this->getEntity(), $this->getEntity());
70
71 $this->assertCount(2, $entities->toArray());
72
73 return $entities;
74 }

The documentation for this class was generated from the following file: