/**
  * Setup
  *
  * @return void
  */
 protected function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->backendAuthSession = $this->getMockBuilder('Magento\\Backend\\Model\\Auth\\Session')->disableOriginalConstructor()->setMethods(['isLoggedIn', 'getUser'])->getMock();
     $this->usersFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\UsersFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->usersModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Users')->disableOriginalConstructor()->getMock();
     $this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->usersFactory->expects($this->any())->method('create')->willReturn($this->usersModel);
     $this->model = new ReportConcurrentAdmins($this->config, $this->backendAuthSession, $this->usersFactory, $this->jsonEncoder);
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->disableOriginalConstructor()->setMethods(['isLoggedIn', 'getCustomerId'])->getMock();
     $this->customerRepository = $this->getMockBuilder('Magento\\Customer\\Api\\CustomerRepositoryInterface')->getMock();
     $this->storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->getMock();
     $this->usersFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\UsersFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->usersModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Users')->disableOriginalConstructor()->getMock();
     $this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->usersFactory->expects($this->any())->method('create')->willReturn($this->usersModel);
     $this->model = new ReportConcurrentUsers($this->config, $this->customerSession, $this->customerRepository, $this->storeManager, $this->usersFactory, $this->jsonEncoder);
 }
 /**
  * Reports concurrent admins to the database reporting_users table
  *
  * @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();
             $jsonData = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getFirstname() . ' ' . $user->getLastname()];
             $modelData = ['type' => 'admin_activity', 'action' => $this->jsonEncoder->encode($jsonData)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
 /**
  * Reports concurrent users to the database reporting_users table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()];
             $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }