Skip to content

Commit 8c9fb75

Browse files
ENGCOM-7951: Replaced deprecated method addError with addErrorMessage #28349
2 parents c5708a3 + 59aa1aa commit 8c9fb75

File tree

42 files changed

+272
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+272
-233
lines changed

app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Customer\Observer;
89

@@ -17,6 +18,7 @@
1718
use Magento\Framework\App\State as AppState;
1819
use Magento\Framework\DataObject;
1920
use Magento\Framework\Escaper;
21+
use Magento\Framework\Event\Observer;
2022
use Magento\Framework\Event\ObserverInterface;
2123
use Magento\Framework\Message\ManagerInterface;
2224
use Magento\Framework\Registry;
@@ -25,6 +27,7 @@
2527
/**
2628
* Customer Observer Model
2729
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2831
*/
2932
class AfterAddressSaveObserver implements ObserverInterface
3033
{
@@ -114,11 +117,11 @@ public function __construct(
114117
/**
115118
* Address after save event handler
116119
*
117-
* @param \Magento\Framework\Event\Observer $observer
120+
* @param Observer $observer
118121
* @return void
119122
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
120123
*/
121-
public function execute(\Magento\Framework\Event\Observer $observer)
124+
public function execute(Observer $observer)
122125
{
123126
/** @var $customerAddress Address */
124127
$customerAddress = $observer->getCustomerAddress();
@@ -280,7 +283,7 @@ protected function addInvalidMessage($customerAddress)
280283
$message[] = (string)__('You will be charged tax.');
281284
}
282285

283-
$this->messageManager->addError(implode(' ', $message));
286+
$this->messageManager->addErrorMessage(implode(' ', $message));
284287

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

310-
$this->messageManager->addError(implode(' ', $message));
313+
$this->messageManager->addErrorMessage(implode(' ', $message));
311314

312315
return $this;
313316
}

app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,23 @@ class AfterAddressSaveObserverTest extends TestCase
8080
protected $appState;
8181

8282
/**
83-
* @var Customer|MockObject
83+
* @var Session|MockObject
8484
*/
85-
protected $customerMock;
85+
protected $customerSessionMock;
8686

8787
/**
88-
* @var Session|MockObject
88+
* @var GroupInterface|MockObject
8989
*/
90-
protected $customerSessionMock;
90+
protected $group;
9191

9292
protected function setUp(): void
9393
{
94-
$this->vat = $this->getMockBuilder(Vat::class)
95-
->disableOriginalConstructor()
96-
->getMock();
97-
98-
$this->helperAddress = $this->getMockBuilder(\Magento\Customer\Helper\Address::class)
99-
->disableOriginalConstructor()
100-
->getMock();
101-
102-
$this->registry = $this->getMockBuilder(Registry::class)
103-
->disableOriginalConstructor()
104-
->getMock();
105-
94+
$this->vat = $this->createMock(Vat::class);
95+
$this->helperAddress = $this->createMock(HelperAddress::class);
96+
$this->registry = $this->createMock(Registry::class);
97+
$this->escaper = $this->createMock(Escaper::class);
98+
$this->appState = $this->createMock(AppState::class);
99+
$this->customerSessionMock = $this->createMock(Session::class);
106100
$this->group = $this->getMockBuilder(GroupInterface::class)
107101
->setMethods(['getId'])
108102
->getMockForAbstractClass();
@@ -114,22 +108,9 @@ protected function setUp(): void
114108

115109
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
116110
->getMockForAbstractClass();
117-
118111
$this->messageManager = $this->getMockBuilder(ManagerInterface::class)
119112
->getMockForAbstractClass();
120113

121-
$this->escaper = $this->getMockBuilder(Escaper::class)
122-
->disableOriginalConstructor()
123-
->getMock();
124-
125-
$this->appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
126-
->disableOriginalConstructor()
127-
->getMock();
128-
129-
$this->customerSessionMock = $this->getMockBuilder(Session::class)
130-
->disableOriginalConstructor()
131-
->getMock();
132-
133114
$this->model = new AfterAddressSaveObserver(
134115
$this->vat,
135116
$this->helperAddress,
@@ -595,7 +576,7 @@ public function testAfterAddressSaveNewGroup(
595576
->with($vatId)
596577
->willReturn($vatId);
597578
$this->messageManager->expects($this->once())
598-
->method('addError')
579+
->method('addErrorMessage')
599580
->with($resultInvalidMessage)
600581
->willReturnSelf();
601582
}
@@ -605,7 +586,7 @@ public function testAfterAddressSaveNewGroup(
605586
->with('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE)
606587
->willReturn('admin@example.com');
607588
$this->messageManager->expects($this->once())
608-
->method('addError')
589+
->method('addErrorMessage')
609590
->with($resultErrorMessage)
610591
->willReturnSelf();
611592
}

app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/Link.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,36 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit;
810

11+
use Magento\Catalog\Controller\Adminhtml\Product\Edit as ProductEdit;
912
use Magento\Downloadable\Helper\Download as DownloadHelper;
13+
use Magento\Downloadable\Helper\File;
14+
use Magento\Downloadable\Model\Link as ModelLink;
1015
use Magento\Framework\App\Response\Http as HttpResponse;
1116

12-
class Link extends \Magento\Catalog\Controller\Adminhtml\Product\Edit
17+
class Link extends ProductEdit
1318
{
1419
/**
15-
* @return \Magento\Downloadable\Model\Link
20+
* Create link
21+
*
22+
* @return ModelLink
1623
*/
1724
protected function _createLink()
1825
{
19-
return $this->_objectManager->create(\Magento\Downloadable\Model\Link::class);
26+
return $this->_objectManager->create(ModelLink::class);
2027
}
2128

2229
/**
23-
* @return \Magento\Downloadable\Model\Link
30+
* Get link
31+
*
32+
* @return ModelLink
2433
*/
2534
protected function _getLink()
2635
{
27-
return $this->_objectManager->get(\Magento\Downloadable\Model\Link::class);
36+
return $this->_objectManager->get(ModelLink::class);
2837
}
2938

3039
/**
@@ -34,10 +43,10 @@ protected function _getLink()
3443
* @param string $resourceType
3544
* @return void
3645
*/
37-
protected function _processDownload($resource, $resourceType)
46+
protected function _processDownload(string $resource, string $resourceType)
3847
{
39-
/* @var $helper \Magento\Downloadable\Helper\Download */
40-
$helper = $this->_objectManager->get(\Magento\Downloadable\Helper\Download::class);
48+
/* @var $helper DownloadHelper */
49+
$helper = $this->_objectManager->get(DownloadHelper::class);
4150
$helper->setResource($resource, $resourceType);
4251

4352
$fileName = $helper->getFilename();
@@ -77,7 +86,7 @@ protected function _processDownload($resource, $resourceType)
7786
//Rendering
7887
$response->clearBody();
7988
$response->sendHeaders();
80-
89+
8190
$helper->output();
8291
}
8392

@@ -90,7 +99,7 @@ public function execute()
9099
{
91100
$linkId = $this->getRequest()->getParam('id', 0);
92101
$type = $this->getRequest()->getParam('type', 0);
93-
/** @var \Magento\Downloadable\Model\Link $link */
102+
/** @var ModelLink $link */
94103
$link = $this->_createLink()->load($linkId);
95104
if ($link->getId()) {
96105
$resource = '';
@@ -101,7 +110,7 @@ public function execute()
101110
$resourceType = DownloadHelper::LINK_TYPE_URL;
102111
} elseif ($link->getLinkType() == DownloadHelper::LINK_TYPE_FILE) {
103112
$resource = $this->_objectManager->get(
104-
\Magento\Downloadable\Helper\File::class
113+
File::class
105114
)->getFilePath(
106115
$this->_getLink()->getBasePath(),
107116
$link->getLinkFile()
@@ -114,7 +123,7 @@ public function execute()
114123
$resourceType = DownloadHelper::LINK_TYPE_URL;
115124
} elseif ($link->getSampleType() == DownloadHelper::LINK_TYPE_FILE) {
116125
$resource = $this->_objectManager->get(
117-
\Magento\Downloadable\Helper\File::class
126+
File::class
118127
)->getFilePath(
119128
$this->_getLink()->getBaseSamplePath(),
120129
$link->getSampleFile()
@@ -125,7 +134,7 @@ public function execute()
125134
try {
126135
$this->_processDownload($resource, $resourceType);
127136
} catch (\Magento\Framework\Exception\LocalizedException $e) {
128-
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
137+
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
129138
}
130139
}
131140
}

app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/Sample.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit;
810

911
use Magento\Downloadable\Helper\Download as DownloadHelper;
12+
use Magento\Downloadable\Model\Sample as ModelSample;
1013

11-
class Sample extends \Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit\Link
14+
class Sample extends Link
1215
{
1316
/**
14-
* @return \Magento\Downloadable\Model\Sample
17+
* Create link
18+
*
19+
* @return ModelSample
1520
*/
1621
protected function _createLink()
1722
{
18-
return $this->_objectManager->create(\Magento\Downloadable\Model\Sample::class);
23+
return $this->_objectManager->create(ModelSample::class);
1924
}
2025

2126
/**
22-
* @return \Magento\Downloadable\Model\Sample
27+
* Get link
28+
*
29+
* @return ModelSample
2330
*/
2431
protected function _getLink()
2532
{
26-
return $this->_objectManager->get(\Magento\Downloadable\Model\Sample::class);
33+
return $this->_objectManager->get(ModelSample::class);
2734
}
2835

2936
/**
@@ -34,7 +41,7 @@ protected function _getLink()
3441
public function execute()
3542
{
3643
$sampleId = $this->getRequest()->getParam('id', 0);
37-
/** @var \Magento\Downloadable\Model\Sample $sample */
44+
/** @var ModelSample $sample */
3845
$sample = $this->_createLink()->load($sampleId);
3946
if ($sample->getId()) {
4047
$resource = '';
@@ -54,7 +61,7 @@ public function execute()
5461
try {
5562
$this->_processDownload($resource, $resourceType);
5663
} catch (\Magento\Framework\Exception\LocalizedException $e) {
57-
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
64+
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
5865
}
5966
}
6067
}

app/code/Magento/Downloadable/Controller/Download/Link.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ public function execute()
125125
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
126126
exit(0);
127127
} catch (\Exception $e) {
128-
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
128+
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
129129
}
130130
} elseif ($status == PurchasedLink::LINK_STATUS_EXPIRED) {
131131
$this->messageManager->addNotice(__('The link has expired.'));
132132
} elseif ($status == PurchasedLink::LINK_STATUS_PENDING || $status == PurchasedLink::LINK_STATUS_PAYMENT_REVIEW
133133
) {
134134
$this->messageManager->addNotice(__('The link is not available.'));
135135
} else {
136-
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
136+
$this->messageManager->addErrorMessage(__('Something went wrong while getting the requested content.'));
137137
}
138138
return $this->_redirect('*/customer/products');
139139
}

app/code/Magento/Downloadable/Controller/Download/LinkSample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function execute()
6969
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
7070
exit(0);
7171
} catch (\Exception $e) {
72-
$this->messageManager->addError(
72+
$this->messageManager->addErrorMessage(
7373
__('Sorry, there was an error getting requested content. Please contact the store owner.')
7474
);
7575
}

app/code/Magento/Downloadable/Test/Unit/Controller/Adminhtml/Downloadable/Product/Edit/SampleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public function testExecuteUrl()
184184
->willReturn('1');
185185
$this->sampleModel->expects($this->any())->method('getSampleType')
186186
->willReturn('url');
187+
$this->sampleModel->expects($this->once())->method('getSampleUrl')
188+
->willReturn('http://example.com/simple.jpg');
187189
$this->objectManager->expects($this->once())->method('create')
188190
->willReturn($this->sampleModel);
189191

app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function testExceptionInUpdateLinkStatus($mimeType, $disposition)
327327
$this->linkPurchasedItem->expects($this->any())->method('setStatus')->with('expired')->willReturnSelf();
328328
$this->linkPurchasedItem->expects($this->any())->method('save')->willThrowException(new \Exception());
329329
$this->messageManager->expects($this->once())
330-
->method('addError')
330+
->method('addErrorMessage')
331331
->with('Something went wrong while getting the requested content.')
332332
->willReturnSelf();
333333
$this->redirect->expects($this->once())->method('redirect')->with($this->response, '*/customer/products', []);
@@ -494,7 +494,7 @@ public function linkNotAvailableDataProvider()
494494
['addNotice', 'expired', 'The link has expired.'],
495495
['addNotice', 'pending', 'The link is not available.'],
496496
['addNotice', 'payment_review', 'The link is not available.'],
497-
['addError', 'wrong_status', 'Something went wrong while getting the requested content.']
497+
['addErrorMessage', 'wrong_status', 'Something went wrong while getting the requested content.']
498498
];
499499
}
500500

app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public function execute()
9999
);
100100
} catch (\Exception $e) {
101101
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
102-
$this->messageManager->addError(__('Please correct the data sent value.'));
102+
$this->messageManager->addErrorMessage(__('Please correct the data sent value.'));
103103
}
104104
} else {
105-
$this->messageManager->addError(__('Please correct the data sent value.'));
105+
$this->messageManager->addErrorMessage(__('Please correct the data sent value.'));
106106
}
107107
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
108108
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function execute()
3535
);
3636
return $resultLayout;
3737
} catch (\Exception $e) {
38-
$this->messageManager->addError($e->getMessage());
38+
$this->messageManager->addErrorMessage($e->getMessage());
3939
}
4040
} else {
41-
$this->messageManager->addError(__('Please correct the data sent value.'));
41+
$this->messageManager->addErrorMessage(__('Please correct the data sent value.'));
4242
}
4343
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
4444
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

0 commit comments

Comments
 (0)