public function testIndexActionException() { $this->request->expects($this->once())->method('isPost')->will($this->returnValue(true)); $exception = new \Exception(); $this->request->expects($this->once())->method('getPost')->will($this->throwException($exception)); $this->logger->expects($this->once())->method('logException')->with($this->identicalTo($exception)); $this->response->expects($this->once())->method('setHttpResponseCode')->with(500); $this->model->execute(); }
public function testRenderMsrpNotRegisteredException() { $this->logger->expects($this->once())->method('logException'); $this->priceInfo->expects($this->once())->method('getPrice')->with($this->equalTo('msrp_price'))->will($this->throwException(new \InvalidArgumentException())); $result = $this->object->toHtml(); //assert price wrapper $this->assertStringStartsWith('<div', $result); //assert css_selector $this->assertRegExp('/[final_price]/', $result); }
public function testMinificationFailed() { $this->prepareAttemptToMinifyMock(false); $this->_asset->expects($this->once())->method('getContent')->will($this->returnValue('content')); $e = new \Exception('test'); $this->_adapter->expects($this->once())->method('minify')->with('content')->will($this->throwException($e)); $this->_logger->expects($this->once())->method('logException'); $this->_staticViewDir->expects($this->never())->method('writeFile'); $this->_asset->expects($this->once())->method('getFilePath')->will($this->returnValue('file_path')); $this->_asset->expects($this->once())->method('getContext')->will($this->returnValue('context')); $this->_asset->expects($this->once())->method('getUrl')->will($this->returnValue('url')); $this->assertEquals('test/library.js', $this->_model->getPath()); }
/** * Test for setting error handler and logging * * @covers \Magento\Framework\Error\Handler::handler * @throws \Exception */ public function testErrorHandlerLogging() { $this->appState->expects($this->any())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT)); $this->logger->expects($this->once())->method('log')->with($this->stringContains('testErrorHandlerLogging'), \Zend_Log::ERR); set_error_handler(array($this->handler, 'handler')); try { trigger_error('testErrorHandlerLogging', E_USER_NOTICE); restore_error_handler(); } catch (\Exception $e) { restore_error_handler(); throw $e; } }
public function testAddException() { $exceptionMessage = 'exception message'; $alternativeText = 'alternative text'; $logText = "Exception message: {$exceptionMessage}\nTrace:"; $messageError = $this->getMockBuilder('Magento\\Framework\\Message\\Error')->setConstructorArgs(array('text' => $alternativeText))->getMock(); $this->messageFactory->expects($this->atLeastOnce())->method('create')->with(MessageInterface::TYPE_ERROR, $alternativeText)->will($this->returnValue($messageError)); $this->logger->expects($this->atLeastOnce())->method('logFile')->with($this->stringStartsWith($logText), \Zend_Log::DEBUG, \Magento\Framework\Logger::LOGGER_EXCEPTION); $messageCollection = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods(array('addMessage'))->getMock(); $messageCollection->expects($this->atLeastOnce())->method('addMessage')->with($messageError); $this->session->expects($this->atLeastOnce())->method('getData')->with(ManagerInterface::DEFAULT_GROUP)->will($this->returnValue($messageCollection)); $exception = new \Exception($exceptionMessage); $this->assertEquals($this->model, $this->model->addException($exception, $alternativeText)); }
/** * @param bool $logQuery * @param bool $logFlag * @param int $expectedCalls * * @dataProvider printLogQueryLoggingDataProvider */ public function testPrintLogQueryLogging($logQuery, $logFlag, $expectedCalls) { $this->collection->setFlag('log_query', $logFlag); $this->loggerMock->expects($this->exactly($expectedCalls))->method('log'); $this->collection->printLogQuery(false, $logQuery, 'some_query'); }
public function testSerialize() { $this->assertNotEmpty($this->_model->serialize()); $this->_logger->expects($this->once())->method('log'); $this->_model->add($this->_items['item1']); }
/** * test import directories without parent */ public function testImportDirectoriesFailureWithoutParent() { $this->directoryMock->expects($this->any())->method('getParentId')->will($this->returnValue(null)); $this->loggerMock->expects($this->any())->method('logException'); $this->directoryDatabase->importDirectories(array()); }