/**
  * Report system cache is flushed to New Relic
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $user = $this->backendAuthSession->getUser();
         if ($user->getId()) {
             $this->deploymentsFactory->create()->setDeployment('Cache Flush', $user->getUsername() . ' flushed the cache.', $user->getUsername());
         }
     }
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlushToNewRelic()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $userMock->expects($this->once())->method('getId')->willReturn('2');
     $this->deploymentsFactory->expects($this->once())->method('create')->willReturn($this->deploymentsModel);
     $this->deploymentsModel->expects($this->once())->method('setDeployment')->willReturnSelf();
     $this->model->execute($eventObserver);
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->collect = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
     $this->counter = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Counter')->disableOriginalConstructor()->setMethods(['getAllProductsCount', 'getConfigurableCount', 'getActiveCatalogSize', 'getCategoryCount', 'getWebsiteCount', 'getStoreViewsCount', 'getCustomerCount'])->getMock();
     $this->cronEventFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\CronEventFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->cronEventModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\CronEvent')->disableOriginalConstructor()->setMethods(['addData', 'sendRequest'])->getMock();
     $this->deploymentsFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Apm\\DeploymentsFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->deploymentsModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Apm\\Deployments')->disableOriginalConstructor()->setMethods(['setDeployment'])->getMock();
     $this->logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
     $this->cronEventFactory->expects($this->any())->method('create')->willReturn($this->cronEventModel);
     $this->deploymentsFactory->expects($this->any())->method('create')->willReturn($this->deploymentsModel);
     $this->model = new ReportNewRelicCron($this->config, $this->collect, $this->counter, $this->cronEventFactory, $this->deploymentsFactory, $this->logger);
 }
 /**
  * Reports current module change status via deployment marker
  *
  * @param array $changesArray
  * @param string $deploymentText
  * @return void
  */
 protected function setModuleChangeStatusDeployment(array $changesArray, $deploymentText = '')
 {
     if (count($changesArray) > 0) {
         foreach ($changesArray as $change) {
             $this->deploymentsFactory->create()->setDeployment($deploymentText, $change, 'cron');
         }
     }
 }