ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
CronJobManagerTest Class Reference
+ Inheritance diagram for CronJobManagerTest:
+ Collaboration diagram for CronJobManagerTest:

Public Member Functions

 testCronManagerActivatesJobWhenJobWasReset ()
 
 testCronManagerNotifiesJobWhenJobGetsActivated ()
 
 testCronManagerNotifiesJobWhenJobGetsDeactivated ()
 

Private Member Functions

 createClockFactoryMock ()
 

Detailed Description

Definition at line 23 of file CronJobManagerTest.php.

Member Function Documentation

◆ createClockFactoryMock()

CronJobManagerTest::createClockFactoryMock ( )
private

Definition at line 25 of file CronJobManagerTest.php.

References ILIAS\GlobalScreen\Provider\__construct().

Referenced by testCronManagerActivatesJobWhenJobWasReset(), testCronManagerNotifiesJobWhenJobGetsActivated(), and testCronManagerNotifiesJobWhenJobGetsDeactivated().

26  {
27  $clock_factory = $this->createMock(ILIAS\Data\Clock\ClockFactory::class);
28  $now = new DateTimeImmutable('@' . time());
29  $clock_factory->method('system')->willReturn(
30  new class ($now) implements \ILIAS\Data\Clock\ClockInterface {
31  private DateTimeImmutable $now;
32 
33  public function __construct(DateTimeImmutable $now)
34  {
35  $this->now = $now;
36  }
37 
38  public function now(): DateTimeImmutable
39  {
40  return $this->now;
41  }
42  }
43  );
44 
45  return $clock_factory;
46  }
Interface Observer Contains several chained tasks and infos about them.
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testCronManagerActivatesJobWhenJobWasReset()

CronJobManagerTest::testCronManagerActivatesJobWhenJobWasReset ( )

Definition at line 48 of file CronJobManagerTest.php.

References createClockFactoryMock().

48  : void
49  {
50  $db = $this->createMock(ilDBInterface::class);
51  $setting = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
52  $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
53  $repository = $this->createMock(ilCronJobRepository::class);
54  $job = $this->createMock(ilCronJob::class);
55  $user = $this->getMockBuilder(ilObjUser::class)
56  ->disableOriginalConstructor()
57  ->onlyMethods(['getId'])
58  ->getMock();
59 
60  $clock_factory = $this->createClockFactoryMock();
61 
62  $cronManager = new ilCronManagerImpl(
63  $repository,
64  $db,
65  $setting,
66  $logger,
67  $clock_factory
68  );
69 
70  $repository->expects($this->once())->method('updateJobResult')->with(
71  $job,
72  $clock_factory->system()->now(),
73  $user,
74  $this->isInstanceOf(ilCronJobResult::class),
75  true
76  );
77 
78  $repository->expects($this->once())->method('resetJob')->with(
79  $job
80  );
81 
82  $repository->expects($this->once())->method('activateJob')->with(
83  $job,
84  $clock_factory->system()->now(),
85  $user,
86  true
87  );
88 
89  $job->expects($this->once())->method('activationWasToggled')->with(
90  $db,
91  $setting,
92  true
93  );
94 
95  $cronManager->resetJob($job, $user);
96  }
+ Here is the call graph for this function:

◆ testCronManagerNotifiesJobWhenJobGetsActivated()

CronJobManagerTest::testCronManagerNotifiesJobWhenJobGetsActivated ( )

Definition at line 98 of file CronJobManagerTest.php.

References createClockFactoryMock().

98  : void
99  {
100  $db = $this->createMock(ilDBInterface::class);
101  $setting = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
102  $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
103  $repository = $this->createMock(ilCronJobRepository::class);
104  $job = $this->createMock(ilCronJob::class);
105  $user = $this->getMockBuilder(ilObjUser::class)
106  ->disableOriginalConstructor()
107  ->onlyMethods(['getId'])
108  ->getMock();
109 
110  $clock_factory = $this->createClockFactoryMock();
111 
112  $cronManager = new ilCronManagerImpl(
113  $repository,
114  $db,
115  $setting,
116  $logger,
117  $clock_factory
118  );
119 
120  $consecutive = [
121  [$job, $clock_factory->system()->now(), $user, true],
122  [$job, $clock_factory->system()->now(), $user, false]
123  ];
124  $repository
125  ->expects($this->exactly(2))
126  ->method('activateJob')
127  ->willReturnCallback(
128  function ($job, $date, $user, $flag) use (&$consecutive): void {
129  list($ejob, $edate, $euser, $eflag) = array_shift($consecutive);
130  $this->assertEquals($ejob, $job);
131  $this->assertEquals($edate, $date);
132  $this->assertEquals($euser, $user);
133  $this->assertEquals($eflag, $flag);
134  }
135  );
136 
137  $job->expects($this->exactly(2))->method('activationWasToggled')->with(
138  $db,
139  $setting,
140  true
141  );
142 
143  $cronManager->activateJob($job, $user, true);
144  $cronManager->activateJob($job, $user, false);
145  }
+ Here is the call graph for this function:

◆ testCronManagerNotifiesJobWhenJobGetsDeactivated()

CronJobManagerTest::testCronManagerNotifiesJobWhenJobGetsDeactivated ( )

Definition at line 147 of file CronJobManagerTest.php.

References createClockFactoryMock().

147  : void
148  {
149  $db = $this->createMock(ilDBInterface::class);
150  $setting = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
151  $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
152  $repository = $this->createMock(ilCronJobRepository::class);
153  $job = $this->createMock(ilCronJob::class);
154  $user = $this->getMockBuilder(ilObjUser::class)
155  ->disableOriginalConstructor()
156  ->onlyMethods(['getId'])
157  ->getMock();
158 
159  $clock_factory = $this->createClockFactoryMock();
160 
161  $cronManager = new ilCronManagerImpl(
162  $repository,
163  $db,
164  $setting,
165  $logger,
166  $clock_factory
167  );
168 
169  $consecutive = [
170  [$job, $clock_factory->system()->now(), $user, true],
171  [$job, $clock_factory->system()->now(), $user, false]
172  ];
173  $repository
174  ->expects($this->exactly(2))
175  ->method('deactivateJob')
176  ->willReturnCallback(
177  function ($job, $date, $user, $flag) use (&$consecutive): void {
178  list($ejob, $edate, $euser, $eflag) = array_shift($consecutive);
179  $this->assertEquals($ejob, $job);
180  $this->assertEquals($edate, $date);
181  $this->assertEquals($euser, $user);
182  $this->assertEquals($eflag, $flag);
183  }
184  );
185 
186  $job->expects($this->exactly(2))->method('activationWasToggled')->with(
187  $db,
188  $setting,
189  false
190  );
191 
192  $cronManager->deactivateJob($job, $user, true);
193  $cronManager->deactivateJob($job, $user, false);
194  }
+ Here is the call graph for this function:

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