Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
ScheduleTest Class Reference
Inheritance diagram for ScheduleTest:

Public Member Functions

 setUp ()
 
 testTryLockJobNoLockedJobsSucceeds ()
 
 testTryLockJobAlreadyLockedFails ()
 
 testTryLockJobAlreadyLockedSucceeds ()
 
 testTryLockJobOtherLockedFails ()
 
 testTryLockJobDifferentJobLocked ()
 

Protected Attributes

 $dateTime
 

Detailed Description

Test \Magento\Cron\Model\Schedule

@magentoDbIsolation enabled

Definition at line 16 of file ScheduleTest.php.

Member Function Documentation

◆ setUp()

setUp ( )

Definition at line 28 of file ScheduleTest.php.

29  {
30  $this->dateTime = Bootstrap::getObjectManager()->create(DateTime::class);
31  $this->scheduleFactory = Bootstrap::getObjectManager()->create(ScheduleFactory::class);
32  }

◆ testTryLockJobAlreadyLockedFails()

testTryLockJobAlreadyLockedFails ( )

If the job is already locked, attempting to lock it again should fail

Definition at line 50 of file ScheduleTest.php.

51  {
52  $schedule = $this->createSchedule("test_job", Schedule::STATUS_RUNNING);
53 
54  $this->assertFalse($schedule->tryLockJob());
55  }

◆ testTryLockJobAlreadyLockedSucceeds()

testTryLockJobAlreadyLockedSucceeds ( )

If the job is already locked but lock time less than 1 day ago, attempting to lock it again should fail

Definition at line 60 of file ScheduleTest.php.

61  {
62  $offsetInThePast = 2*24*60*60;
63 
64  $oldSchedule = $this->scheduleFactory->create()
65  ->setCronExpr("* * * * *")
66  ->setJobCode("test_job")
67  ->setStatus(Schedule::STATUS_RUNNING)
68  ->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp() - $offsetInThePast))
69  ->setScheduledAt(strftime('%Y-%m-%d %H:%M', $this->dateTime->gmtTimestamp() - $offsetInThePast + 60))
70  ->setExecutedAt(strftime('%Y-%m-%d %H:%M', $this->dateTime->gmtTimestamp() - $offsetInThePast + 61));
71  $oldSchedule->save();
72 
73  $schedule = $this->createSchedule("test_job", Schedule::STATUS_PENDING);
74 
75  $this->assertTrue($schedule->tryLockJob());
76  }

◆ testTryLockJobDifferentJobLocked()

testTryLockJobDifferentJobLocked ( )

Should be able to lock a job if a job with a different code is locked

Definition at line 92 of file ScheduleTest.php.

93  {
94  $this->createSchedule("test_job_other", Schedule::STATUS_RUNNING);
95  $schedule = $this->createSchedule("test_job", Schedule::STATUS_PENDING);
96 
97  $this->assertTrue($schedule->tryLockJob());
98  }

◆ testTryLockJobNoLockedJobsSucceeds()

testTryLockJobNoLockedJobsSucceeds ( )

If there are no currently locked jobs, locking one of them should succeed

Definition at line 37 of file ScheduleTest.php.

38  {
39  for ($i = 1; $i < 6; $i++) {
40  $this->createSchedule("test_job", Schedule::STATUS_PENDING, 60 * $i);
41  }
42  $schedule = $this->createSchedule("test_job", Schedule::STATUS_PENDING);
43 
44  $this->assertTrue($schedule->tryLockJob());
45  }
$i
Definition: gallery.phtml:31

◆ testTryLockJobOtherLockedFails()

testTryLockJobOtherLockedFails ( )

If there's a job already locked, should not be able to lock another job

Definition at line 81 of file ScheduleTest.php.

82  {
83  $this->createSchedule("test_job", Schedule::STATUS_RUNNING);
84  $schedule = $this->createSchedule("test_job", Schedule::STATUS_PENDING, 60);
85 
86  $this->assertFalse($schedule->tryLockJob());
87  }

Field Documentation

◆ $dateTime

$dateTime
protected

Definition at line 26 of file ScheduleTest.php.


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