Skip to content

Commit a413cbb

Browse files
committed
MAGETWO-58222: Cron separate process
2 parents 680087e + 04f47fa commit a413cbb

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

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

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -600,74 +600,74 @@ public function testDispatchNotGenerate()
600600
public function testDispatchGenerate()
601601
{
602602
$jobConfig = [
603-
'test_group' => [
604-
'default' => [
605-
'test_job1' => [
606-
'instance' => 'CronJob',
607-
'method' => 'execute',
608-
],
603+
'default' => [
604+
'test_job1' => [
605+
'instance' => 'CronJob',
606+
'method' => 'execute',
609607
],
610608
],
611609
];
612610

613-
$this->_config->expects($this->at(0))->method('getJobs')->will($this->returnValue($jobConfig));
614611
$jobs = [
615-
'test_group' => [
616-
'default' => [
617-
'job1' => ['config_path' => 'test/path'],
618-
'job2' => ['schedule' => ''],
619-
'job3' => ['schedule' => '* * * * *'],
620-
],
612+
'default' => [
613+
'job1' => ['config_path' => 'test/path'],
614+
'job2' => ['schedule' => ''],
615+
'job3' => ['schedule' => '* * * * *'],
621616
],
622617
];
623-
$this->_config->expects($this->at(1))->method('getJobs')->will($this->returnValue($jobs));
624-
$this->_request->expects($this->any())->method('getParam')->will($this->returnValue('test_group'));
618+
$this->_config->expects($this->at(0))->method('getJobs')->willReturn($jobConfig);
619+
$this->_config->expects($this->at(1))->method('getJobs')->willReturn($jobs);
620+
$this->_request->expects($this->any())->method('getParam')->willReturn('default');
625621
$this->_cache->expects(
626622
$this->at(0)
627623
)->method(
628624
'load'
629625
)->with(
630-
$this->equalTo(ProcessCronQueueObserver::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . 'test_group')
631-
)->will(
632-
$this->returnValue(time() - 10000000)
633-
);
626+
$this->equalTo(ProcessCronQueueObserver::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . 'default')
627+
)->willReturn(time() - 10000000);
634628
$this->_cache->expects(
635629
$this->at(2)
636630
)->method(
637631
'load'
638632
)->with(
639-
$this->equalTo(ProcessCronQueueObserver::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . 'test_group')
640-
)->will(
641-
$this->returnValue(time() + 10000000)
642-
);
633+
$this->equalTo(ProcessCronQueueObserver::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . 'default')
634+
)->willReturn(time() + 10000000);
643635

644-
$this->_scopeConfig->expects($this->at(0))->method('getValue')->will($this->returnValue(0));
636+
$this->_scopeConfig->expects($this->any())->method('getValue')->willReturnMap(
637+
[
638+
[
639+
'system/cron/default/schedule_generate_every',
640+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
641+
null,
642+
0
643+
],
644+
[
645+
'system/cron/default/schedule_ahead_for',
646+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
647+
null,
648+
2
649+
]
650+
]
651+
);
645652

646-
$scheduleMethods = ['getJobCode', 'getScheduledAt', 'trySchedule', 'unsScheduleId', 'save', '__wakeup'];
647653
$schedule = $this->getMockBuilder(
648654
\Magento\Cron\Model\Schedule::class
649655
)->setMethods(
650-
$scheduleMethods
656+
['getJobCode', 'save', 'getScheduledAt', 'unsScheduleId', 'trySchedule', 'getCollection']
651657
)->disableOriginalConstructor()->getMock();
652-
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('job_code1'));
653-
$schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue('* * * * *'));
654-
$schedule->expects($this->any())->method('unsScheduleId')->will($this->returnSelf());
655-
$schedule->expects($this->any())->method('trySchedule')->will($this->returnSelf());
658+
$schedule->expects($this->any())->method('getJobCode')->willReturn('job_code1');
659+
$schedule->expects($this->once())->method('getScheduledAt')->willReturn('* * * * *');
660+
$schedule->expects($this->any())->method('unsScheduleId')->willReturnSelf();
661+
$schedule->expects($this->any())->method('trySchedule')->willReturnSelf();
662+
$schedule->expects($this->any())->method('getCollection')->willReturn($this->_collection);
663+
$schedule->expects($this->exactly(1))->method('save')->willReturnSelf();
656664

657665
$this->_collection->addItem(new \Magento\Framework\DataObject());
658666
$this->_collection->addItem($schedule);
659667

660668
$this->_cache->expects($this->any())->method('save');
661669

662-
$scheduleMock = $this->getMockBuilder(
663-
\Magento\Cron\Model\Schedule::class
664-
)->disableOriginalConstructor()->setMethods(
665-
['getCollection', '__wakeup']
666-
)->getMock();
667-
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
668-
$this->_scheduleFactory->expects($this->any())->method('create')->will($this->returnValue($scheduleMock));
669-
670-
$this->_scheduleFactory->expects($this->any())->method('create')->will($this->returnValue($schedule));
670+
$this->_scheduleFactory->expects($this->any())->method('create')->willReturn($schedule);
671671

672672
$this->_observer->execute($this->observer);
673673
}

0 commit comments

Comments
 (0)