25 $this->helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
27 $this->resourceJobMock = $this->getMockBuilder(\
Magento\Cron\Model\
ResourceModel\Schedule::class)
28 ->disableOriginalConstructor()
29 ->setMethods([
'trySetJobUniqueStatusAtomic',
'__wakeup',
'getIdFieldName'])
30 ->getMockForAbstractClass();
32 $this->resourceJobMock->expects($this->any())
33 ->method(
'getIdFieldName')
34 ->will($this->returnValue(
'id'));
42 public function testSetCronExpr($cronExpression, $expected)
46 $model = $this->helper->getObject(\
Magento\Cron\Model\Schedule::class);
49 $model->setCronExpr($cronExpression);
53 $this->assertEquals(
$result, $expected);
67 [
'1 2 3 4 5', [1, 2, 3, 4, 5]],
68 [
'1 2 3 4 5 6', [1, 2, 3, 4, 5, 6]],
69 [
'a b c d e', [
'a',
'b',
'c',
'd',
'e']],
70 [
'* * * * *', [
'*',
'*',
'*',
'*',
'*']],
72 [
'0 * * * *', [
'0',
'*',
'*',
'*',
'*']],
73 [
'59 * * * *', [
'59',
'*',
'*',
'*',
'*']],
74 [
', * * * *', [
',',
'*',
'*',
'*',
'*']],
75 [
'1-2 * * * *', [
'1-2',
'*',
'*',
'*',
'*']],
76 [
'0/5 * * * *', [
'0/5',
'*',
'*',
'*',
'*']],
78 [
'* 0 * * *', [
'*',
'0',
'*',
'*',
'*']],
79 [
'* 59 * * *', [
'*',
'59',
'*',
'*',
'*']],
80 [
'* , * * *', [
'*',
',',
'*',
'*',
'*']],
81 [
'* 1-2 * * *', [
'*',
'1-2',
'*',
'*',
'*']],
82 [
'* 0/5 * * *', [
'*',
'0/5',
'*',
'*',
'*']],
84 [
'* * 0 * *', [
'*',
'*',
'0',
'*',
'*']],
85 [
'* * 23 * *', [
'*',
'*',
'23',
'*',
'*']],
86 [
'* * , * *', [
'*',
'*',
',',
'*',
'*']],
87 [
'* * 1-2 * *', [
'*',
'*',
'1-2',
'*',
'*']],
88 [
'* * 0/5 * *', [
'*',
'*',
'0/5',
'*',
'*']],
90 [
'* * * 1 *', [
'*',
'*',
'*',
'1',
'*']],
91 [
'* * * 31 *', [
'*',
'*',
'*',
'31',
'*']],
92 [
'* * * , *', [
'*',
'*',
'*',
',',
'*']],
93 [
'* * * 1-2 *', [
'*',
'*',
'*',
'1-2',
'*']],
94 [
'* * * 0/5 *', [
'*',
'*',
'*',
'0/5',
'*']],
95 [
'* * * ? *', [
'*',
'*',
'*',
'?',
'*']],
96 [
'* * * L *', [
'*',
'*',
'*',
'L',
'*']],
97 [
'* * * W *', [
'*',
'*',
'*',
'W',
'*']],
98 [
'* * * C *', [
'*',
'*',
'*',
'C',
'*']],
100 [
'* * * * 0', [
'*',
'*',
'*',
'*',
'0']],
101 [
'* * * * 11', [
'*',
'*',
'*',
'*',
'11']],
102 [
'* * * * ,', [
'*',
'*',
'*',
'*',
',']],
103 [
'* * * * 1-2', [
'*',
'*',
'*',
'*',
'1-2']],
104 [
'* * * * 0/5', [
'*',
'*',
'*',
'*',
'0/5']],
105 [
'* * * * JAN', [
'*',
'*',
'*',
'*',
'JAN']],
106 [
'* * * * DEC', [
'*',
'*',
'*',
'*',
'DEC']],
107 [
'* * * * JAN-DEC', [
'*',
'*',
'*',
'*',
'JAN-DEC']],
109 [
'* * * * * 1', [
'*',
'*',
'*',
'*',
'*',
'1']],
110 [
'* * * * * 7', [
'*',
'*',
'*',
'*',
'*',
'7']],
111 [
'* * * * * ,', [
'*',
'*',
'*',
'*',
'*',
',']],
112 [
'* * * * * 1-2', [
'*',
'*',
'*',
'*',
'*',
'1-2']],
113 [
'* * * * * 0/5', [
'*',
'*',
'*',
'*',
'*',
'0/5']],
114 [
'* * * * * ?', [
'*',
'*',
'*',
'*',
'*',
'?']],
115 [
'* * * * * L', [
'*',
'*',
'*',
'*',
'*',
'L']],
116 [
'* * * * * 6#3', [
'*',
'*',
'*',
'*',
'*',
'6#3']],
117 [
'* * * * * SUN', [
'*',
'*',
'*',
'*',
'*',
'SUN']],
118 [
'* * * * * SAT', [
'*',
'*',
'*',
'*',
'*',
'SAT']],
119 [
'* * * * * SUN-SAT', [
'*',
'*',
'*',
'*',
'*',
'SUN-SAT']],
128 public function testSetCronExprException($cronExpression)
132 $model = $this->helper->getObject(\
Magento\Cron\Model\Schedule::class);
135 $model->setCronExpr($cronExpression);
161 public function testTrySchedule($scheduledAt, $cronExprArr, $expected)
165 $model = $this->helper->getObject(
166 \
Magento\Cron\Model\Schedule::class
170 $model->setScheduledAt($scheduledAt);
171 $model->setCronExprArr($cronExprArr);
177 $this->assertEquals($expected,
$result);
180 public function testTryScheduleWithConversionToAdminStoreTime()
182 $scheduledAt =
'2011-12-13 14:15:16';
183 $cronExprArr = [
'*',
'*',
'*',
'*',
'*'];
186 $timezoneConverter = $this->createMock(\
Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
187 $timezoneConverter->expects($this->once())
190 ->willReturn(
new \DateTime($scheduledAt));
193 $model = $this->helper->getObject(
194 \
Magento\Cron\Model\Schedule::class,
195 [
'timezoneConverter' => $timezoneConverter]
199 $model->setScheduledAt($scheduledAt);
200 $model->setCronExprArr($cronExprArr);
214 $date =
'2011-12-13 14:15:16';
217 [$date,
null,
false],
218 [$date,
false,
false],
220 [$date,
null,
false],
221 [$date,
false,
false],
222 [strtotime($date), [
'*',
'*',
'*',
'*',
'*'],
true],
223 [strtotime($date), [
'15',
'*',
'*',
'*',
'*'],
true],
224 [strtotime($date), [
'*',
'14',
'*',
'*',
'*'],
true],
225 [strtotime($date), [
'*',
'*',
'13',
'*',
'*'],
true],
226 [strtotime($date), [
'*',
'*',
'*',
'12',
'*'],
true],
227 [strtotime(
'Monday'), [
'*',
'*',
'*',
'*',
'1'],
true],
237 public function testMatchCronExpression($cronExpressionPart, $dateTimePart, $expectedResult)
241 $model = $this->helper->getObject(\
Magento\Cron\Model\Schedule::class);
244 $result =
$model->matchCronExpression($cronExpressionPart, $dateTimePart);
247 $this->assertEquals($expectedResult,
$result);
262 [
'0,1,20', 20,
true],
263 [
'0,1,22', 2,
false],
279 [
'0-20/5', 10,
true],
280 [
'0-20/5', 21,
false],
281 [
'0-20/5', 25,
false],
294 public function testMatchCronExpressionException($cronExpressionPart)
300 $model = $this->helper->getObject(\
Magento\Cron\Model\Schedule::class);
303 $model->matchCronExpression($cronExpressionPart, $dateTimePart);
324 public function testGetNumeric($param, $expectedResult)
328 $model = $this->helper->getObject(\
Magento\Cron\Model\Schedule::class);
334 $this->assertEquals($expectedResult,
$result);
348 [PHP_INT_MAX, PHP_INT_MAX],
365 public function testTryLockJobSuccess()
369 $this->resourceJobMock->expects($this->once())
370 ->method(
'trySetJobUniqueStatusAtomic')
372 ->will($this->returnValue(
true));
375 $model = $this->helper->getObject(
376 \
Magento\Cron\Model\Schedule::class,
378 'resource' => $this->resourceJobMock
381 $model->setId($scheduleId);
382 $this->assertEquals(0,
$model->getStatus());
389 public function testTryLockJobFailure()
393 $this->resourceJobMock->expects($this->once())
394 ->method(
'trySetJobUniqueStatusAtomic')
396 ->will($this->returnValue(
false));
399 $model = $this->helper->getObject(
400 \
Magento\Cron\Model\Schedule::class,
402 'resource' => $this->resourceJobMock
405 $model->setId($scheduleId);
406 $this->assertEquals(0,
$model->getStatus());
410 $this->assertEquals(0,
$model->getStatus());
matchCronExpressionExceptionDataProvider()
tryScheduleDataProvider()
matchCronExpressionDataProvider()
setCronExprDataProvider()
setCronExprExceptionDataProvider()