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