Skip to content

Replaced deprecated method addError with addErrorMessage #28349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Observer;

Expand All @@ -17,6 +18,7 @@
use Magento\Framework\App\State as AppState;
use Magento\Framework\DataObject;
use Magento\Framework\Escaper;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Registry;
Expand All @@ -25,6 +27,7 @@
/**
* Customer Observer Model
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class AfterAddressSaveObserver implements ObserverInterface
{
Expand Down Expand Up @@ -114,11 +117,11 @@ public function __construct(
/**
* Address after save event handler
*
* @param \Magento\Framework\Event\Observer $observer
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
public function execute(Observer $observer)
{
/** @var $customerAddress Address */
$customerAddress = $observer->getCustomerAddress();
Expand Down Expand Up @@ -280,7 +283,7 @@ protected function addInvalidMessage($customerAddress)
$message[] = (string)__('You will be charged tax.');
}

$this->messageManager->addError(implode(' ', $message));
$this->messageManager->addErrorMessage(implode(' ', $message));

return $this;
}
Expand All @@ -307,7 +310,7 @@ protected function addErrorMessage($customerAddress)
$email = $this->scopeConfig->getValue('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE);
$message[] = (string)__('If you believe this is an error, please contact us at %1', $email);

$this->messageManager->addError(implode(' ', $message));
$this->messageManager->addErrorMessage(implode(' ', $message));

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,23 @@ class AfterAddressSaveObserverTest extends TestCase
protected $appState;

/**
* @var Customer|MockObject
* @var Session|MockObject
*/
protected $customerMock;
protected $customerSessionMock;

/**
* @var Session|MockObject
* @var GroupInterface|MockObject
*/
protected $customerSessionMock;
protected $group;

protected function setUp(): void
{
$this->vat = $this->getMockBuilder(Vat::class)
->disableOriginalConstructor()
->getMock();

$this->helperAddress = $this->getMockBuilder(\Magento\Customer\Helper\Address::class)
->disableOriginalConstructor()
->getMock();

$this->registry = $this->getMockBuilder(Registry::class)
->disableOriginalConstructor()
->getMock();

$this->vat = $this->createMock(Vat::class);
$this->helperAddress = $this->createMock(HelperAddress::class);
$this->registry = $this->createMock(Registry::class);
$this->escaper = $this->createMock(Escaper::class);
$this->appState = $this->createMock(AppState::class);
$this->customerSessionMock = $this->createMock(Session::class);
$this->group = $this->getMockBuilder(GroupInterface::class)
->setMethods(['getId'])
->getMockForAbstractClass();
Expand All @@ -114,22 +108,9 @@ protected function setUp(): void

$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
->getMockForAbstractClass();

$this->messageManager = $this->getMockBuilder(ManagerInterface::class)
->getMockForAbstractClass();

$this->escaper = $this->getMockBuilder(Escaper::class)
->disableOriginalConstructor()
->getMock();

$this->appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
->disableOriginalConstructor()
->getMock();

$this->customerSessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->getMock();

$this->model = new AfterAddressSaveObserver(
$this->vat,
$this->helperAddress,
Expand Down Expand Up @@ -595,7 +576,7 @@ public function testAfterAddressSaveNewGroup(
->with($vatId)
->willReturn($vatId);
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with($resultInvalidMessage)
->willReturnSelf();
}
Expand All @@ -605,7 +586,7 @@ public function testAfterAddressSaveNewGroup(
->with('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE)
->willReturn('[email protected]');
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with($resultErrorMessage)
->willReturnSelf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit;

use Magento\Catalog\Controller\Adminhtml\Product\Edit as ProductEdit;
use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Downloadable\Helper\File;
use Magento\Downloadable\Model\Link as ModelLink;
use Magento\Framework\App\Response\Http as HttpResponse;

class Link extends \Magento\Catalog\Controller\Adminhtml\Product\Edit
class Link extends ProductEdit
{
/**
* @return \Magento\Downloadable\Model\Link
* Create link
*
* @return ModelLink
*/
protected function _createLink()
{
return $this->_objectManager->create(\Magento\Downloadable\Model\Link::class);
return $this->_objectManager->create(ModelLink::class);
}

/**
* @return \Magento\Downloadable\Model\Link
* Get link
*
* @return ModelLink
*/
protected function _getLink()
{
return $this->_objectManager->get(\Magento\Downloadable\Model\Link::class);
return $this->_objectManager->get(ModelLink::class);
}

/**
Expand All @@ -34,10 +43,10 @@ protected function _getLink()
* @param string $resourceType
* @return void
*/
protected function _processDownload($resource, $resourceType)
protected function _processDownload(string $resource, string $resourceType)
{
/* @var $helper \Magento\Downloadable\Helper\Download */
$helper = $this->_objectManager->get(\Magento\Downloadable\Helper\Download::class);
/* @var $helper DownloadHelper */
$helper = $this->_objectManager->get(DownloadHelper::class);
$helper->setResource($resource, $resourceType);

$fileName = $helper->getFilename();
Expand Down Expand Up @@ -77,7 +86,7 @@ protected function _processDownload($resource, $resourceType)
//Rendering
$response->clearBody();
$response->sendHeaders();

$helper->output();
}

Expand All @@ -90,7 +99,7 @@ public function execute()
{
$linkId = $this->getRequest()->getParam('id', 0);
$type = $this->getRequest()->getParam('type', 0);
/** @var \Magento\Downloadable\Model\Link $link */
/** @var ModelLink $link */
$link = $this->_createLink()->load($linkId);
if ($link->getId()) {
$resource = '';
Expand All @@ -101,7 +110,7 @@ public function execute()
$resourceType = DownloadHelper::LINK_TYPE_URL;
} elseif ($link->getLinkType() == DownloadHelper::LINK_TYPE_FILE) {
$resource = $this->_objectManager->get(
\Magento\Downloadable\Helper\File::class
File::class
)->getFilePath(
$this->_getLink()->getBasePath(),
$link->getLinkFile()
Expand All @@ -114,7 +123,7 @@ public function execute()
$resourceType = DownloadHelper::LINK_TYPE_URL;
} elseif ($link->getSampleType() == DownloadHelper::LINK_TYPE_FILE) {
$resource = $this->_objectManager->get(
\Magento\Downloadable\Helper\File::class
File::class
)->getFilePath(
$this->_getLink()->getBaseSamplePath(),
$link->getSampleFile()
Expand All @@ -125,7 +134,7 @@ public function execute()
try {
$this->_processDownload($resource, $resourceType);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit;

use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Downloadable\Model\Sample as ModelSample;

class Sample extends \Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit\Link
class Sample extends Link
{
/**
* @return \Magento\Downloadable\Model\Sample
* Create link
*
* @return ModelSample
*/
protected function _createLink()
{
return $this->_objectManager->create(\Magento\Downloadable\Model\Sample::class);
return $this->_objectManager->create(ModelSample::class);
}

/**
* @return \Magento\Downloadable\Model\Sample
* Get link
*
* @return ModelSample
*/
protected function _getLink()
{
return $this->_objectManager->get(\Magento\Downloadable\Model\Sample::class);
return $this->_objectManager->get(ModelSample::class);
}

/**
Expand All @@ -34,7 +41,7 @@ protected function _getLink()
public function execute()
{
$sampleId = $this->getRequest()->getParam('id', 0);
/** @var \Magento\Downloadable\Model\Sample $sample */
/** @var ModelSample $sample */
$sample = $this->_createLink()->load($sampleId);
if ($sample->getId()) {
$resource = '';
Expand All @@ -54,7 +61,7 @@ public function execute()
try {
$this->_processDownload($resource, $resourceType);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Downloadable/Controller/Download/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ public function execute()
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
} catch (\Exception $e) {
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
}
} elseif ($status == PurchasedLink::LINK_STATUS_EXPIRED) {
$this->messageManager->addNotice(__('The link has expired.'));
} elseif ($status == PurchasedLink::LINK_STATUS_PENDING || $status == PurchasedLink::LINK_STATUS_PAYMENT_REVIEW
) {
$this->messageManager->addNotice(__('The link is not available.'));
} else {
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
}
return $this->_redirect('*/customer/products');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function execute()
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
} catch (\Exception $e) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__('Sorry, there was an error getting requested content. Please contact the store owner.')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ public function testExecuteUrl()
->willReturn('1');
$this->sampleModel->expects($this->any())->method('getSampleType')
->willReturn('url');
$this->sampleModel->expects($this->once())->method('getSampleUrl')
->willReturn('http://example.com/simple.jpg');
$this->objectManager->expects($this->once())->method('create')
->willReturn($this->sampleModel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function testExceptionInUpdateLinkStatus($mimeType, $disposition)
$this->linkPurchasedItem->expects($this->any())->method('setStatus')->with('expired')->willReturnSelf();
$this->linkPurchasedItem->expects($this->any())->method('save')->willThrowException(new \Exception());
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with('Something went wrong while getting the requested content.')
->willReturnSelf();
$this->redirect->expects($this->once())->method('redirect')->with($this->response, '*/customer/products', []);
Expand Down Expand Up @@ -494,7 +494,7 @@ public function linkNotAvailableDataProvider()
['addNotice', 'expired', 'The link has expired.'],
['addNotice', 'pending', 'The link is not available.'],
['addNotice', 'payment_review', 'The link is not available.'],
['addError', 'wrong_status', 'Something went wrong while getting the requested content.']
['addErrorMessage', 'wrong_status', 'Something went wrong while getting the requested content.']
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public function execute()
);
} catch (\Exception $e) {
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->messageManager->addError(__('Please correct the data sent value.'));
$this->messageManager->addErrorMessage(__('Please correct the data sent value.'));
}
} else {
$this->messageManager->addError(__('Please correct the data sent value.'));
$this->messageManager->addErrorMessage(__('Please correct the data sent value.'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function execute()
);
return $resultLayout;
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
}
} else {
$this->messageManager->addError(__('Please correct the data sent value.'));
$this->messageManager->addErrorMessage(__('Please correct the data sent value.'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
Loading