public function testResetPasswordActionCoreExceptionWarn() { $warningText = 'Warning'; $customerId = 1; $this->_request->expects($this->once())->method('getParam')->with($this->equalTo('customer_id'), $this->equalTo(0))->will($this->returnValue($customerId)); // Setup a core exception to return $exception = new \Magento\Framework\Model\Exception($warningText); $error = new \Magento\Framework\Message\Warning('Something Not So Bad happened'); $exception->addMessage($error); $this->_acctServiceMock->expects($this->once())->method('getCustomer')->with($customerId)->will($this->throwException($exception)); // Verify Warning is converted to an Error and message text is set to exception text $this->messageManager->expects($this->once())->method('addMessage')->with($this->equalTo(new \Magento\Framework\Message\Error($warningText))); $this->_testedObject->execute(); }
/** * Validate model before saving it * * @return $this * @throws \Magento\Framework\Model\Exception */ protected function _validateBeforeSave() { $validator = $this->_getValidatorBeforeSave(); if ($validator && !$validator->isValid($this)) { $errors = $validator->getMessages(); $exception = new \Magento\Framework\Model\Exception(implode(PHP_EOL, $errors)); foreach ($errors as $errorMessage) { $exception->addMessage(new \Magento\Framework\Message\Error($errorMessage)); } throw $exception; } return $this; }