Skip to content

Commit 0bf86e6

Browse files
committed
magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer
1 parent c743624 commit 0bf86e6

File tree

17 files changed

+239
-165
lines changed

17 files changed

+239
-165
lines changed

app/code/Magento/Customer/Controller/Account/Confirm.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public function execute()
151151
$customerId = $this->getRequest()->getParam('id', false);
152152
$key = $this->getRequest()->getParam('key', false);
153153
if (empty($customerId) || empty($key)) {
154-
throw new \Exception(__('Bad request.'));
154+
$this->messageManager->addErrorMessage(__('Bad request.'));
155+
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
156+
return $resultRedirect->setUrl($this->_redirect->error($url));
155157
}
156158

157159
// log in and send greeting email

app/code/Magento/Customer/Controller/Account/Confirmation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -15,6 +14,9 @@
1514
use Magento\Customer\Api\AccountManagementInterface;
1615
use Magento\Framework\Exception\State\InvalidTransitionException;
1716

17+
/**
18+
* Class Confirmation
19+
*/
1820
class Confirmation extends \Magento\Customer\Controller\AbstractAccount
1921
{
2022
/**

app/code/Magento/Customer/Controller/Account/LoginPost.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Magento\Framework\Phrase;
2727

2828
/**
29+
* Class LoginPost
2930
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3031
*/
3132
class LoginPost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface

app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -9,6 +8,9 @@
98
use Magento\Framework\App\Action\HttpPostActionInterface;
109
use Magento\Framework\Exception\NoSuchEntityException;
1110

11+
/**
12+
* Class Delete
13+
*/
1214
class Delete extends \Magento\Customer\Controller\Adminhtml\Group implements HttpPostActionInterface
1315
{
1416
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function execute()
7373

7474
/**
7575
* Return component referer url
76+
*
7677
* TODO: Technical dept referer url should be implement as a part of Action configuration in appropriate way
7778
*
7879
* @return null|string

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Customer\Api\Data\CustomerInterface;
1010
use Magento\Framework\Exception\NoSuchEntityException;
1111

12+
/**
13+
* Class Edit
14+
*/
1215
class Edit extends \Magento\Customer\Controller\Adminhtml\Index implements HttpGetActionInterface
1316
{
1417
/**
@@ -33,14 +36,11 @@ public function execute()
3336
$customer = $this->_customerRepository->getById($customerId);
3437
$customerData['account'] = $this->customerMapper->toFlatArray($customer);
3538
$customerData['account'][CustomerInterface::ID] = $customerId;
36-
try {
37-
$addresses = $customer->getAddresses();
38-
foreach ($addresses as $address) {
39-
$customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address);
40-
$customerData['address'][$address->getId()]['id'] = $address->getId();
41-
}
42-
} catch (NoSuchEntityException $e) {
43-
//do nothing
39+
40+
$addresses = $customer->getAddresses();
41+
foreach ($addresses as $address) {
42+
$customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address);
43+
$customerData['address'][$address->getId()]['id'] = $address->getId();
4444
}
4545
} catch (NoSuchEntityException $e) {
4646
$this->messageManager->addExceptionMessage($e, __('Something went wrong while editing the customer.'));

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ public function execute()
128128

129129
$postItems = $this->getRequest()->getParam('items', []);
130130
if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
131-
return $resultJson->setData([
132-
'messages' => [__('Please correct the data sent.')],
133-
'error' => true,
134-
]);
131+
return $resultJson->setData(
132+
[
133+
'messages' => [__('Please correct the data sent.')],
134+
'error' => true,
135+
]
136+
);
135137
}
136138

137139
foreach (array_keys($postItems) as $customerId) {
@@ -147,10 +149,12 @@ public function execute()
147149
$this->getEmailNotification()->credentialsChanged($this->getCustomer(), $currentCustomer->getEmail());
148150
}
149151

150-
return $resultJson->setData([
151-
'messages' => $this->getErrorMessages(),
152-
'error' => $this->isErrorExists()
153-
]);
152+
return $resultJson->setData(
153+
[
154+
'messages' => $this->getErrorMessages(),
155+
'error' => $this->isErrorExists()
156+
]
157+
);
154158
}
155159

156160
/**

app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,12 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad
255255

256256
$this->requestMock->expects($this->any())
257257
->method('getParam')
258-
->willReturnMap([
259-
['id', false, $customerId],
260-
['key', false, $key],
261-
]);
258+
->willReturnMap(
259+
[
260+
['id', false, $customerId],
261+
['key', false, $key],
262+
]
263+
);
262264

263265
$this->customerRepositoryMock->expects($this->any())
264266
->method('getById')
@@ -372,11 +374,13 @@ public function testSuccessRedirect(
372374

373375
$this->requestMock->expects($this->any())
374376
->method('getParam')
375-
->willReturnMap([
376-
['id', false, $customerId],
377-
['key', false, $key],
378-
['back_url', false, $backUrl],
379-
]);
377+
->willReturnMap(
378+
[
379+
['id', false, $customerId],
380+
['key', false, $key],
381+
['back_url', false, $backUrl],
382+
]
383+
);
380384

381385
$this->customerRepositoryMock->expects($this->any())
382386
->method('getById')

app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,13 @@ public function testSuccessMessage(
346346

347347
$this->requestMock->expects($this->any())
348348
->method('getParam')
349-
->willReturnMap([
350-
['password', null, $password],
351-
['password_confirmation', null, $password],
352-
['is_subscribed', false, true],
353-
]);
349+
->willReturnMap(
350+
[
351+
['password', null, $password],
352+
['password_confirmation', null, $password],
353+
['is_subscribed', false, true],
354+
]
355+
);
354356

355357
$this->customerMock->expects($this->once())
356358
->method('setAddresses')
@@ -477,11 +479,13 @@ public function testSuccessRedirect(
477479

478480
$this->requestMock->expects($this->any())
479481
->method('getParam')
480-
->willReturnMap([
481-
['password', null, $password],
482-
['password_confirmation', null, $password],
483-
['is_subscribed', false, true],
484-
]);
482+
->willReturnMap(
483+
[
484+
['password', null, $password],
485+
['password_confirmation', null, $password],
486+
['is_subscribed', false, true],
487+
]
488+
);
485489

486490
$this->customerMock->expects($this->once())
487491
->method('setAddresses')
@@ -508,10 +512,12 @@ public function testSuccessRedirect(
508512

509513
$this->urlMock->expects($this->any())
510514
->method('getUrl')
511-
->willReturnMap([
512-
['*/*/index', ['_secure' => true], $successUrl],
513-
['*/*/create', ['_secure' => true], $successUrl],
514-
]);
515+
->willReturnMap(
516+
[
517+
['*/*/index', ['_secure' => true], $successUrl],
518+
['*/*/create', ['_secure' => true], $successUrl],
519+
]
520+
);
515521
$this->redirectMock->expects($this->once())
516522
->method('success')
517523
->with($this->equalTo($successUrl))

app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ protected function setUp()
9393

9494
$this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
9595
->disableOriginalConstructor()
96-
->setMethods([
97-
'isLoggedIn',
98-
'setCustomerDataAsLoggedIn',
99-
'regenerateId',
100-
'setUsername',
101-
])
96+
->setMethods(
97+
[
98+
'isLoggedIn',
99+
'setCustomerDataAsLoggedIn',
100+
'regenerateId',
101+
'setUsername',
102+
]
103+
)
102104
->getMock();
103105

104106
$this->accountManagement = $this->getMockBuilder(\Magento\Customer\Api\AccountManagementInterface::class)
@@ -253,10 +255,12 @@ public function testExecuteSuccessCustomRedirect()
253255
$this->request->expects($this->once())
254256
->method('getPost')
255257
->with('login')
256-
->willReturn([
257-
'username' => $username,
258-
'password' => $password,
259-
]);
258+
->willReturn(
259+
[
260+
'username' => $username,
261+
'password' => $password,
262+
]
263+
);
260264

261265
$customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
262266
->getMockForAbstractClass();
@@ -335,10 +339,12 @@ public function testExecuteSuccess()
335339
$this->request->expects($this->once())
336340
->method('getPost')
337341
->with('login')
338-
->willReturn([
339-
'username' => $username,
340-
'password' => $password,
341-
]);
342+
->willReturn(
343+
[
344+
'username' => $username,
345+
'password' => $password,
346+
]
347+
);
342348

343349
$customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
344350
->getMockForAbstractClass();
@@ -426,10 +432,12 @@ public function testExecuteWithException(
426432
$this->request->expects($this->once())
427433
->method('getPost')
428434
->with('login')
429-
->willReturn([
430-
'username' => $username,
431-
'password' => $password,
432-
]);
435+
->willReturn(
436+
[
437+
'username' => $username,
438+
'password' => $password,
439+
]
440+
);
433441

434442
$exception = new $exceptionData['exception'](__($exceptionData['message']));
435443

@@ -488,10 +496,12 @@ protected function prepareContext()
488496

489497
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
490498
->disableOriginalConstructor()
491-
->setMethods([
492-
'isPost',
493-
'getPost',
494-
])
499+
->setMethods(
500+
[
501+
'isPost',
502+
'getPost',
503+
]
504+
)
495505
->getMock();
496506

497507
$this->resultRedirect = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)

app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function testExecuteWithException()
183183
->willReturn(34);
184184
$exception = new \Exception('Exception');
185185
$this->messageManager->expects($this->once())
186-
->method('addErrorMessage')
186+
->method('addComplexErrorMessage')
187187
->with(__('We can\'t delete the address right now.'))
188188
->willThrowException($exception);
189189
$this->messageManager->expects($this->once())

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testExecuteWithTaxClassAndException()
175175
->with('customer/group')
176176
->willThrowException($exception);
177177
$this->messageManager->expects($this->once())
178-
->method('addErrorMessage')
178+
->method('addError')
179179
->with('Exception');
180180
$this->dataObjectProcessorMock->expects($this->once())
181181
->method('buildOutputDataArray')

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ protected function prepareMocksForErrorMessagesProcessing()
291291
->willReturn('Error text');
292292
$this->resultJson->expects($this->once())
293293
->method('setData')
294-
->with([
295-
'messages' => ['Error text'],
296-
'error' => true,
297-
])
294+
->with(
295+
[
296+
'messages' => ['Error text'],
297+
'error' => true,
298+
]
299+
)
298300
->willReturnSelf();
299301
}
300302

@@ -340,10 +342,12 @@ public function testExecuteWithoutItems()
340342
$this->resultJson
341343
->expects($this->once())
342344
->method('setData')
343-
->with([
344-
'messages' => [__('Please correct the data sent.')],
345-
'error' => true,
346-
])
345+
->with(
346+
[
347+
'messages' => [__('Please correct the data sent.')],
348+
'error' => true,
349+
]
350+
)
347351
->willReturnSelf();
348352
$this->assertSame($this->resultJson, $this->controller->execute());
349353
}

0 commit comments

Comments
 (0)