Пример #1
0
 /**
  * Testing \Magento\Framework\Validator\Exception::getMessage
  * @return void
  */
 public function testGetMessage()
 {
     $expectedMessage = 'error1' . PHP_EOL . 'error2' . PHP_EOL . 'error3';
     $messages = ['field1' => ['error1', 'error2'], 'field2' => ['error3']];
     $exception = new \Magento\Framework\Validator\Exception(null, null, $messages);
     $this->assertEquals($expectedMessage, $exception->getMessage());
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 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();
 }