Exemplo n.º 1
0
 protected function setUp()
 {
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\AreaList')->getArea('crontab')->load(\Magento\Framework\App\Area::PART_CONFIG);
     $request = Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Console\\Request');
     $request->setParams(['group' => 'default', 'standaloneProcessStarted' => '0']);
     $this->_model = Bootstrap::getObjectManager()->create('Magento\\Cron\\Model\\Observer', ['request' => $request]);
     $this->_model->dispatch('this argument is not used');
 }
Exemplo n.º 2
0
 public function testMissedJobsCleanedInTime()
 {
     /* 1. Initialize dependencies of _generate() method which is called first */
     $jobConfig = ['test_group' => ['test_job1' => ['instance' => 'CronJob', 'method' => 'execute']]];
     // This item was scheduled 2 days ago
     $schedule1 = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->setMethods(['getExecutedAt', 'getScheduledAt', 'getStatus', 'delete', '__wakeup'])->getMock();
     $schedule1->expects($this->any())->method('getExecutedAt')->will($this->returnValue(null));
     $schedule1->expects($this->any())->method('getScheduledAt')->will($this->returnValue('-2 day -1 hour'));
     $schedule1->expects($this->any())->method('getStatus')->will($this->returnValue(Schedule::STATUS_MISSED));
     //we expect this job be deleted from the list
     $schedule1->expects($this->once())->method('delete')->will($this->returnValue(true));
     // This item was scheduled 1 day ago
     $schedule2 = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->setMethods(['getExecutedAt', 'getScheduledAt', 'getStatus', 'delete', '__wakeup'])->getMock();
     $schedule2->expects($this->any())->method('getExecutedAt')->will($this->returnValue(null));
     $schedule2->expects($this->any())->method('getScheduledAt')->will($this->returnValue('-1 day'));
     $schedule2->expects($this->any())->method('getStatus')->will($this->returnValue(Schedule::STATUS_MISSED));
     //we don't expect this job be deleted from the list
     $schedule2->expects($this->never())->method('delete');
     $this->_collection->addItem($schedule1);
     $this->_config->expects($this->once())->method('getJobs')->will($this->returnValue($jobConfig));
     //get configuration value CACHE_KEY_LAST_HISTORY_CLEANUP_AT in the "_generate()"
     $this->_cache->expects($this->at(0))->method('load')->will($this->returnValue(time() + 10000000));
     //get configuration value CACHE_KEY_LAST_HISTORY_CLEANUP_AT in the "_cleanup()"
     $this->_cache->expects($this->at(1))->method('load')->will($this->returnValue(time() - 10000000));
     $this->_scopeConfig->expects($this->at(0))->method('getValue')->with($this->equalTo('system/cron/test_group/use_separate_process'))->will($this->returnValue(0));
     $this->_scopeConfig->expects($this->at(1))->method('getValue')->with($this->equalTo('system/cron/test_group/schedule_generate_every'))->will($this->returnValue(0));
     $this->_scopeConfig->expects($this->at(2))->method('getValue')->with($this->equalTo('system/cron/test_group/history_cleanup_every'))->will($this->returnValue(0));
     $this->_scopeConfig->expects($this->at(3))->method('getValue')->with($this->equalTo('system/cron/test_group/schedule_lifetime'))->will($this->returnValue(2 * 24 * 60));
     $this->_scopeConfig->expects($this->at(4))->method('getValue')->with($this->equalTo('system/cron/test_group/history_success_lifetime'))->will($this->returnValue(0));
     $this->_scopeConfig->expects($this->at(5))->method('getValue')->with($this->equalTo('system/cron/test_group/history_failure_lifetime'))->will($this->returnValue(0));
     /* 2. Initialize dependencies of _cleanup() method which is called second */
     $scheduleMock = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->getMock();
     $scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
     $this->_scheduleFactory->expects($this->at(0))->method('create')->will($this->returnValue($scheduleMock));
     $collection = $this->getMockBuilder('Magento\\Cron\\Model\\Resource\\Schedule\\Collection')->setMethods(['addFieldToFilter', 'load', '__wakeup'])->disableOriginalConstructor()->getMock();
     $collection->expects($this->any())->method('addFieldToFilter')->will($this->returnSelf());
     $collection->expects($this->any())->method('load')->will($this->returnSelf());
     $collection->addItem($schedule1);
     $collection->addItem($schedule2);
     $scheduleMock = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->getMock();
     $scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($collection));
     $this->_scheduleFactory->expects($this->at(1))->method('create')->will($this->returnValue($scheduleMock));
     $this->_observer->dispatch('');
 }
Exemplo n.º 3
0
 /**
  * Test case without saved cron jobs in data base
  */
 public function testDispatchCleanup()
 {
     $jobConfig = ['test_group' => ['test_job1' => ['instance' => 'CronJob', 'method' => 'execute']]];
     $schedule = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->setMethods(['getExecutedAt', 'getStatus', 'delete', '__wakeup'])->getMock();
     $schedule->expects($this->any())->method('getExecutedAt')->will($this->returnValue('-1 day'));
     $schedule->expects($this->any())->method('getStatus')->will($this->returnValue('success'));
     $this->_collection->addItem($schedule);
     $this->_config->expects($this->once())->method('getJobs')->will($this->returnValue($jobConfig));
     $this->_cache->expects($this->at(0))->method('load')->will($this->returnValue(time() + 10000000));
     $this->_cache->expects($this->at(1))->method('load')->will($this->returnValue(time() - 10000000));
     $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue(0));
     $scheduleMock = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->getMock();
     $scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
     $this->_scheduleFactory->expects($this->at(0))->method('create')->will($this->returnValue($scheduleMock));
     $collection = $this->getMockBuilder('Magento\\Cron\\Model\\Resource\\Schedule\\Collection')->setMethods(['addFieldToFilter', 'load', '__wakeup'])->disableOriginalConstructor()->getMock();
     $collection->expects($this->any())->method('addFieldToFilter')->will($this->returnSelf());
     $collection->expects($this->any())->method('load')->will($this->returnSelf());
     $collection->addItem($schedule);
     $scheduleMock = $this->getMockBuilder('Magento\\Cron\\Model\\Schedule')->disableOriginalConstructor()->getMock();
     $scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($collection));
     $this->_scheduleFactory->expects($this->at(1))->method('create')->will($this->returnValue($scheduleMock));
     $this->_observer->dispatch('');
 }
Exemplo n.º 4
0
 protected function setUp()
 {
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\AreaList')->getArea('crontab')->load(\Magento\Framework\App\Area::PART_CONFIG);
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Cron\\Model\\Observer');
     $this->_model->dispatch('this argument is not used');
 }