/** * 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); }
/** * Tests client request will fail */ public function testSetDeploymentRequestFail() { $data = $this->getDataVariables(); $this->zendClientMock->expects($this->once())->method('setUri')->with($data['uri'])->willReturnSelf(); $this->zendClientMock->expects($this->once())->method('setMethod')->with($data['method'])->willReturnSelf(); $this->zendClientMock->expects($this->once())->method('setHeaders')->with($data['headers'])->willReturnSelf(); $this->zendClientMock->expects($this->once())->method('setParameterPost')->with($data['params'])->willReturnSelf(); $this->configMock->expects($this->once())->method('getNewRelicApiUrl')->willReturn($data['uri']); $this->configMock->expects($this->once())->method('getNewRelicApiKey')->willReturn($data['api_key']); $this->configMock->expects($this->once())->method('getNewRelicAppName')->willReturn($data['app_name']); $this->configMock->expects($this->once())->method('getNewRelicAppId')->willReturn($data['app_id']); $this->zendClientMock->expects($this->once())->method('request')->willThrowException(new \Zend_Http_Client_Exception()); $this->loggerMock->expects($this->once())->method('critical'); $this->zendClientFactoryMock->expects($this->once())->method('create')->willReturn($this->zendClientMock); $this->assertInternalType('bool', $this->model->setDeployment($data['description'], $data['change'], $data['user'])); }
/** * 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()); }