Skip to content

Commit 1a8e4a5

Browse files
committed
Schedule generation was broken
1 parent e719669 commit 1a8e4a5

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exist
454454
if ($schedule->trySchedule()) {
455455
// time matches cron expression
456456
$schedule->save();
457-
return;
458457
}
459458
}
460459
}

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -530,23 +530,19 @@ public function testDispatchGenerate()
530530
{
531531
$jobConfig = [
532532
'test_group' => [
533-
'default' => [
534-
'test_job1' => [
535-
'instance' => 'CronJob',
536-
'method' => 'execute',
537-
],
533+
'test_job1' => [
534+
'instance' => 'CronJob',
535+
'method' => 'execute',
538536
],
539537
],
540538
];
541539

542540
$this->_config->expects($this->at(0))->method('getJobs')->will($this->returnValue($jobConfig));
543541
$jobs = [
544542
'test_group' => [
545-
'default' => [
546-
'job1' => ['config_path' => 'test/path'],
547-
'job2' => ['schedule' => ''],
548-
'job3' => ['schedule' => '* * * * *'],
549-
],
543+
'job1' => ['config_path' => 'test/path'],
544+
'job2' => ['schedule' => ''],
545+
'job3' => ['schedule' => '* * * * *'],
550546
],
551547
];
552548
$this->_config->expects($this->at(1))->method('getJobs')->will($this->returnValue($jobs));
@@ -570,32 +566,40 @@ public function testDispatchGenerate()
570566
$this->returnValue(time() + 10000000)
571567
);
572568

573-
$this->_scopeConfig->expects($this->at(0))->method('getValue')->will($this->returnValue(0));
569+
$this->_scopeConfig->expects($this->any())->method('getValue')->willReturnMap(
570+
[
571+
[
572+
'system/cron/test_group/schedule_generate_every',
573+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
574+
null,
575+
0
576+
],
577+
[
578+
'system/cron/test_group/schedule_ahead_for',
579+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
580+
null,
581+
2
582+
]
583+
]
584+
);
574585

575-
$scheduleMethods = ['getJobCode', 'getScheduledAt', 'trySchedule', 'unsScheduleId', 'save', '__wakeup'];
576586
$schedule = $this->getMockBuilder(
577587
'Magento\Cron\Model\Schedule'
578588
)->setMethods(
579-
$scheduleMethods
589+
['getJobCode', 'getScheduledAt', 'trySchedule', 'unsScheduleId', 'save', '__wakeup', 'getCollection']
580590
)->disableOriginalConstructor()->getMock();
581591
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('job_code1'));
582592
$schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue('* * * * *'));
583593
$schedule->expects($this->any())->method('unsScheduleId')->will($this->returnSelf());
584594
$schedule->expects($this->any())->method('trySchedule')->will($this->returnSelf());
595+
$schedule->expects($this->any())->method('getCollection')->willReturn($this->_collection);
596+
$schedule->expects($this->atLeastOnce())->method('save')->willReturnSelf();
585597

586598
$this->_collection->addItem(new \Magento\Framework\DataObject());
587599
$this->_collection->addItem($schedule);
588600

589601
$this->_cache->expects($this->any())->method('save');
590602

591-
$scheduleMock = $this->getMockBuilder(
592-
'Magento\Cron\Model\Schedule'
593-
)->disableOriginalConstructor()->setMethods(
594-
['getCollection', '__wakeup']
595-
)->getMock();
596-
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
597-
$this->_scheduleFactory->expects($this->any())->method('create')->will($this->returnValue($scheduleMock));
598-
599603
$this->_scheduleFactory->expects($this->any())->method('create')->will($this->returnValue($schedule));
600604

601605
$this->_observer->execute($this->observer);

0 commit comments

Comments
 (0)