/**
  * Reports Modules and module changes to the database reporting_module_status table
  *
  * @return \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo
  */
 public function report()
 {
     if ($this->config->isNewRelicEnabled()) {
         $moduleData = $this->collect->getModuleData();
         if (count($moduleData['changes']) > 0) {
             foreach ($moduleData['changes'] as $change) {
                 switch ($change['type']) {
                     case Config::ENABLED:
                         $modelData = ['type' => Config::MODULE_ENABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                     case Config::DISABLED:
                         $modelData = ['type' => Config::MODULE_DISABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                     case Config::INSTALLED:
                         $modelData = ['type' => Config::MODULE_INSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                     case Config::UNINSTALLED:
                         $modelData = ['type' => Config::MODULE_UNINSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                 }
                 /** @var \Magento\NewRelicReporting\Model\System $systemModel */
                 $systemModel = $this->systemFactory->create();
                 $systemModel->setData($modelData);
                 $systemModel->save();
             }
         }
     }
     return $this;
 }
 /**
  *  Reports current total module counts to Insights
  *
  * @return void
  */
 protected function reportModules()
 {
     $moduleData = $this->collect->getModuleData(false);
     $moduleDataChanges = $moduleData['changes'];
     if (count($moduleDataChanges) > 0) {
         $enabledChangeArray = [];
         $disabledChangeArray = [];
         $installedChangeArray = [];
         $uninstalledChangeArray = [];
         foreach ($moduleDataChanges as $change) {
             switch ($change['type']) {
                 case Config::ENABLED:
                     $enabledChangeArray[] = $change['name'] . '-' . $change['setup_version'];
                     break;
                 case Config::DISABLED:
                     $disabledChangeArray[] = $change['name'] . '-' . $change['setup_version'];
                     break;
                 case Config::INSTALLED:
                     $installedChangeArray[] = $change['name'] . '-' . $change['setup_version'];
                     break;
                 case Config::UNINSTALLED:
                     $uninstalledChangeArray[] = $change['name'] . '-' . $change['setup_version'];
                     break;
             }
         }
         $this->setModuleChangeStatusDeployment($enabledChangeArray, 'Modules Enabled');
         $this->setModuleChangeStatusDeployment($disabledChangeArray, 'Modules Disabled');
         $this->setModuleChangeStatusDeployment($installedChangeArray, 'Modules Installed');
         $this->setModuleChangeStatusDeployment($uninstalledChangeArray, 'Modules Uninstalled');
     }
     $this->addCustomParameters([Config::MODULES_ENABLED => $moduleData[Config::ENABLED]]);
     $this->addCustomParameters([Config::MODULES_DISABLED => $moduleData[Config::DISABLED]]);
     $this->addCustomParameters([Config::MODULES_INSTALLED => $moduleData[Config::INSTALLED]]);
 }
 /**
  * Test case when module is enabled
  *
  * @return void
  */
 public function testReportReportModulesInfo()
 {
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->collectMock->expects($this->once())->method('getModuleData')->willReturn(['installed' => '1', 'uninstalled' => '1', 'enabled' => '1', 'disabled' => '1', 'changes' => [['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled']]]);
     $this->systemModelMock->expects($this->any())->method('setData')->willReturnSelf();
     $this->systemModelMock->expects($this->any())->method('save')->willReturnSelf();
     $this->assertSame($this->model, $this->model->report());
 }
Esempio n. 4
0
 /**
  * Tests modules data returns array and saving in DB
  *
  * @dataProvider itemDataProvider
  * @return void
  */
 public function testGetModuleDataRefreshOrStatement($data)
 {
     $moduleCollectionMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\ResourceModel\\Module\\Collection')->disableOriginalConstructor()->getMock();
     /** @var \Magento\NewRelicReporting\Model\Module|\PHPUnit_Framework_MockObject_MockObject $itemMock */
     $itemMock = $this->getMock('Magento\\NewRelicReporting\\Model\\Module', ['getName', 'getData', 'setData', 'getState', 'save'], [], '', false);
     $modulesMockArray = ['Module_Name1' => ['name' => 'Module_Name1', 'setup_version' => '2.0.0', 'sequence' => []]];
     $itemMock->setData($data);
     $testChangesMockArray = ['entity_id' => '3', 'name' => 'Name', 'active' => 'false', 'state' => 'enabled', 'setup_version' => '2.0.0', 'some_param' => 'some_value', 'updated_at' => '2015-09-02 18:38:17'];
     $itemMockArray = [$itemMock];
     $enabledModulesMockArray = ['Module_Name2'];
     $allModulesMockArray = ['Module_Name1', 'Module_Name2'];
     $this->moduleCollectionFactoryMock->expects($this->any())->method('create')->willReturn($moduleCollectionMock);
     $this->moduleFactoryMock->expects($this->any())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->any())->method('setData')->willReturnSelf();
     $itemMock->expects($this->any())->method('save')->willReturnSelf();
     $itemMock->expects($this->any())->method('getState')->willReturn($data['state']);
     $itemMock->expects($this->any())->method('getName')->willReturn($data['name']);
     $moduleCollectionMock->expects($this->any())->method('getItems')->willReturn($itemMockArray);
     $itemMock->expects($this->any())->method('getData')->willReturn($testChangesMockArray);
     $this->fullModuleListMock->expects($this->once())->method('getAll')->willReturn($modulesMockArray);
     $this->fullModuleListMock->expects($this->any())->method('getNames')->willReturn($allModulesMockArray);
     $this->moduleListMock->expects($this->any())->method('getNames')->willReturn($enabledModulesMockArray);
     $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will($this->returnValue(true));
     $this->assertInternalType('array', $this->model->getModuleData());
 }
 /**
  * Test case when module is enabled and request is failed
  *
  * @return void
  */
 public function testReportNewRelicCronRequestFailed()
 {
     $testModuleData = ['changes' => [['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled']], 'enabled' => 1, 'disabled' => 1, 'installed' => 1];
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->collect->expects($this->once())->method('getModuleData')->willReturn($testModuleData);
     $this->counter->expects($this->once())->method('getAllProductsCount');
     $this->counter->expects($this->once())->method('getConfigurableCount');
     $this->counter->expects($this->once())->method('getActiveCatalogSize');
     $this->counter->expects($this->once())->method('getCategoryCount');
     $this->counter->expects($this->once())->method('getWebsiteCount');
     $this->counter->expects($this->once())->method('getStoreViewsCount');
     $this->counter->expects($this->once())->method('getCustomerCount');
     $this->cronEventModel->expects($this->once())->method('addData')->willReturnSelf();
     $this->cronEventModel->expects($this->once())->method('sendRequest');
     $this->cronEventModel->expects($this->once())->method('sendRequest')->willThrowException(new \Exception());
     $this->logger->expects($this->once())->method('critical');
     $this->deploymentsModel->expects($this->any())->method('setDeployment');
     $this->assertSame($this->model, $this->model->report());
 }