示例#1
1
 /**
  * Update items stock status and low stock date.
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if (!$this->newRelicWrapper->isExtensionInstalled()) {
             $this->config->disableModule();
             $this->messageManager->addError(__('The New Relic integration requires the newrelic-php5 agent, which is not installed. More 
                     information on installing the agent is available <a target="_blank" href="%1">here</a>.', 'https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-overview'), $this->messageManager->getDefaultGroup());
         }
     }
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportProductDeletedToNewRelic()
 {
     /** @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);
     $this->newRelicWrapper->expects($this->once())->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
示例#3
0
 /**
  * Test case when module is enabled in config and php extension is installed
  *
  * @return void
  */
 public function testCheckConfig()
 {
     /** @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);
     $this->newRelicWrapper->expects($this->once())->method('isExtensionInstalled')->willReturn(false);
     $this->config->expects($this->once())->method('disableModule');
     $this->messageManager->expects($this->once())->method('addError');
     $this->model->execute($eventObserver);
 }
 /**
  * Adds New Relic custom parameters per adminhtml request for current admin user, if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->backendAuthSession->isLoggedIn()) {
             $user = $this->backendAuthSession->getUser();
             $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER_ID, $user->getId());
             $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER, $user->getUsername());
             $this->newRelicWrapper->addCustomParameter(Config::ADMIN_NAME, $user->getFirstname() . ' ' . $user->getLastname());
         }
     }
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentAdminsToNewRelic()
 {
     /** @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);
     $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
 /**
  * Reports any products created or updated to New Relic
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $observer->getEvent()->getProduct();
         if ($product->isObjectNew()) {
             $this->newRelicWrapper->addCustomParameter(\Magento\NewRelicReporting\Model\Config::PRODUCT_CHANGE, 'create');
         } else {
             $this->newRelicWrapper->addCustomParameter(\Magento\NewRelicReporting\Model\Config::PRODUCT_CHANGE, 'update');
         }
     }
 }
 /**
  * Adds New Relic custom parameters per request for store, website, and logged in user if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::STORE, $this->storeManager->getStore()->getName());
         $this->newRelicWrapper->addCustomParameter(Config::WEBSITE, $this->storeManager->getWebsite()->getName());
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_ID, $customer->getId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_NAME, $customer->getFirstname() . ' ' . $customer->getLastname());
         }
     }
 }
 /**
  * Test case when module is enabled in config and product updating
  *
  * @dataProvider actionDataProvider
  * @return void
  */
 public function testReportProductUpdatedToNewRelic($isNewObject)
 {
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getProduct'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('isObjectNew')->willReturn($isNewObject);
     $event->expects($this->once())->method('getProduct')->willReturn($product);
     $this->newRelicWrapper->expects($this->once())->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
 /**
  * Reports orders placed to New Relic
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Sales\Model\Order $order */
         $order = $observer->getEvent()->getOrder();
         $itemCount = $order->getTotalItemCount();
         if (!is_numeric($itemCount) && empty($itemCount)) {
             $itemCount = $order->getTotalQtyOrdered();
         }
         $this->newRelicWrapper->addCustomParameter(Config::ORDER_PLACED, 1);
         $this->newRelicWrapper->addCustomParameter(Config::ORDER_ITEMS, $itemCount);
         $this->newRelicWrapper->addCustomParameter(Config::ORDER_VALUE, $order->getBaseGrandTotal());
     }
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportOrderPlacedToNewRelic()
 {
     $testTotal = '1.00';
     $testItemCount = null;
     $testTotalQtyOrderedCount = 1;
     /** @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);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getOrder'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getOrder')->willReturn($order);
     $order->expects($this->once())->method('getBaseGrandTotal')->willReturn($testTotal);
     $order->expects($this->once())->method('getTotalItemCount')->willReturn($testItemCount);
     $order->expects($this->once())->method('getTotalQtyOrdered')->willReturn($testTotalQtyOrderedCount);
     $this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentUsersToNewRelic()
 {
     $testCustomerId = 1;
     /** @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);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->customerRepository->expects($this->once())->method('getById')->willReturn($customerMock);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
     $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
     $this->newRelicWrapper->expects($this->exactly(4))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
 /**
  * Reports any products deleted to New Relic
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::PRODUCT_CHANGE, 'delete');
     }
 }