Esempio n. 1
0
 public function testUpdateDbWithException()
 {
     $this->databaseConfig->expects($this->once())->method('isAutoUpdate')->willReturn(true);
     $e = new \Exception();
     $this->updaterSelected->expects($this->once())->method('update')->willThrowException($e);
     $this->logger->expects($this->once())->method('critical')->with($e);
     $this->assertSame($this->cronUpdateDb, $this->cronUpdateDb->execute());
 }
Esempio n. 2
0
 public function testUpdate()
 {
     $availableDatabases = ['db_code_1', 'db_code_2', 'db_cod_3'];
     $countAvailableDatabases = count($availableDatabases);
     $this->config->expects($this->once())->method('getAvailableDatabases')->willReturn($availableDatabases);
     $this->updater->expects($this->exactly($countAvailableDatabases))->method('update')->withConsecutive(['db_code_1'], ['db_code_2'], ['db_cod_3']);
     $this->updaterSelected->update();
 }
Esempio n. 3
0
 /**
  * @return $this
  */
 public function execute()
 {
     if (!$this->databaseConfig->isAutoUpdate()) {
         return $this;
     }
     try {
         $this->updaterSelected->update();
     } catch (\Exception $e) {
         $this->logger->critical($e);
     }
     return $this;
 }
Esempio n. 4
0
 public function testUpdate()
 {
     $statusInfo = 'some status info';
     $data = ['status' => 'success', 'message' => __('Database(s) successfully updated.'), 'status_info' => $statusInfo];
     $this->resultJson->expects($this->once())->method('setData')->with($data)->willReturnSelf();
     $this->updaterSelected->expects($this->once())->method('update')->willReturnSelf();
     $statusBlock = $this->getMockBuilder('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->disableOriginalConstructor()->getMock();
     $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface');
     $this->layoutFactory->expects($this->once())->method('create')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->with('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->willReturn($statusBlock);
     $statusBlock->expects($this->once())->method('getDbStatus')->willReturn($statusInfo);
     $this->logger->expects($this->never())->method('critical');
     $this->assertSame($this->resultJson, $this->controllerUpdate->execute());
 }
Esempio n. 5
0
 /**
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $response = ['status' => 'success'];
     try {
         $this->updaterSelected->update();
         $response['message'] = __('Database(s) successfully updated.');
         $response['status_info'] = $this->getStatusHtml();
     } catch (LocalizedException $e) {
         $response['status'] = 'error';
         $response['message'] = $e->getMessage();
     } catch (\Exception $e) {
         $this->logger->critical($e);
         $response['status'] = 'error';
         $response['message'] = __('An error occurred during DB updating.');
     }
     /** @var Json $resultJson */
     $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     $resultJson->setData($response);
     return $resultJson;
 }