Skip to content

Commit ba88cfd

Browse files
author
Yurii Torbyk
committed
MAGETWO-33813: Replace Magento\Framework\Model\Exception to LocalizedException
1 parent 5f3c23c commit ba88cfd

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function execute()
3535
$resultRedirect->setPath('customer/index');
3636
return $resultRedirect;
3737
} catch (\Magento\Framework\Validator\ValidatorException $exception) {
38-
$messages = $exception->getMessages();
38+
$messages = $exception->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR);
3939
if (!count($messages)) {
4040
$messages = $exception->getMessage();
4141
}

dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ public function testResetPasswordActionCoreException()
324324
);
325325

326326
// Setup a core exception to return
327-
$error = 'Something Bad happened';
328-
$exception = new \Magento\Framework\Validator\ValidatorException($error);
329-
$exception->addError('Something Bad happened');
327+
$exception = new \Magento\Framework\Validator\ValidatorException();
328+
$error = new \Magento\Framework\Message\Error('Something Bad happened');
329+
$exception->addMessage($error);
330330

331331
$this->_customerRepositoryMock->expects(
332332
$this->once()
@@ -341,7 +341,7 @@ public function testResetPasswordActionCoreException()
341341
// Verify error message is set
342342
$this->messageManager->expects($this->once())
343343
->method('addMessage')
344-
->with($this->equalTo(new \Magento\Framework\Message\Error($error)));
344+
->with($this->equalTo($error));
345345

346346
$this->_testedObject->execute();
347347
}
@@ -351,34 +351,26 @@ public function testResetPasswordActionCoreExceptionWarn()
351351
$warningText = 'Warning';
352352
$customerId = 1;
353353

354-
$this->_request->expects(
355-
$this->once()
356-
)->method(
357-
'getParam'
358-
)->with(
359-
$this->equalTo('customer_id'),
360-
$this->equalTo(0)
361-
)->will(
362-
$this->returnValue($customerId)
363-
);
354+
$this->_request->expects($this->once())
355+
->method('getParam')
356+
->with($this->equalTo('customer_id'), $this->equalTo(0))
357+
->will($this->returnValue($customerId));
364358

365359
// Setup a core exception to return
366360
$exception = new \Magento\Framework\Validator\ValidatorException($warningText);
367-
$error = 'Something Not So Bad happened';
368-
$exception->addError($error);
361+
362+
$error = new \Magento\Framework\Message\Warning('Something Not So Bad happened');
363+
$exception->addMessage($error);
369364

370365
$this->_customerRepositoryMock->expects($this->once())
371366
->method('getById')
372367
->with($customerId)
373368
->will($this->throwException($exception));
374369

375370
// Verify Warning is converted to an Error and message text is set to exception text
376-
$this->messageManager->expects(
377-
$this->once()
378-
)->method(
379-
'addMessage'
380-
)->with(
381-
$this->equalTo(new \Magento\Framework\Message\Error($warningText))
371+
$this->messageManager->expects($this->once())
372+
->method('addMessage')
373+
->with($this->equalTo(new \Magento\Framework\Message\Error($warningText))
382374
);
383375

384376
$this->_testedObject->execute();

0 commit comments

Comments
 (0)