ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

References ilCronJobResult\CODE_NO_RESULT, and ilCronJobResult\STATUS_OK.

Referenced by testCollectionCanBeChanged(), testEffectiveScheduleCanBeDetermined(), and testEntityCollectionCanBeCreatedWithItems().

41  : ilCronJobEntity {
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  }
+ Here is the caller graph for this function:

◆ testCollectionCanBeChanged()

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

Definition at line 81 of file CronJobEntityTest.php.

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

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)
+ Here is the call graph for this function:

◆ testCollectionCanBeFilteredAndSliced()

CronJobEntityTest::testCollectionCanBeFilteredAndSliced ( ilCronJobEntities  $entities)
Parameters
ilCronJobEntities$entitiestestCollectionCanBeChanged

Definition at line 94 of file CronJobEntityTest.php.

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

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  }
slice(int $offset, ?int $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection.
filter(callable $callable)
Returns all the elements of this collection that satisfy the predicate $callable. ...
+ Here is the call graph for this function:

◆ testEffectiveScheduleCanBeDetermined()

CronJobEntityTest::testEffectiveScheduleCanBeDetermined ( )

Definition at line 103 of file CronJobEntityTest.php.

References getEntity(), ilCronJob\SCHEDULE_TYPE_DAILY, ilCronJob\SCHEDULE_TYPE_IN_HOURS, and ilCronJob\SCHEDULE_TYPE_IN_MINUTES.

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  }
getEntity(ilCronJob $job_instance=null, int $schedule_type=ilCronJob::SCHEDULE_TYPE_IN_MINUTES, int $schedule_value=5, bool $is_plugin=false)
const SCHEDULE_TYPE_IN_MINUTES
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_DAILY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_IN_HOURS
This will be replaced with an ENUM in ILIAS 9
+ Here is the call graph for this function:

◆ testEntityCollectionCanBeCreatedWithItems()

CronJobEntityTest::testEntityCollectionCanBeCreatedWithItems ( )

Definition at line 67 of file CronJobEntityTest.php.

References getEntity().

68  {
69  $entities = new ilCronJobEntities($this->getEntity(), $this->getEntity());
70 
71  $this->assertCount(2, $entities->toArray());
72 
73  return $entities;
74  }
getEntity(ilCronJob $job_instance=null, int $schedule_type=ilCronJob::SCHEDULE_TYPE_IN_MINUTES, int $schedule_value=5, bool $is_plugin=false)
+ Here is the call graph for this function:

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