Skip to content

Commit 54b6382

Browse files
committed
Updated the unit test, fix and additional issue #18170
1 parent 030b223 commit 54b6382

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function __construct(
394394
SessionManagerInterface $sessionManager = null,
395395
SaveHandlerInterface $saveHandler = null,
396396
CollectionFactory $visitorCollectionFactory = null,
397-
AddressRegistry $addressRegistry
397+
AddressRegistry $addressRegistry = null
398398
) {
399399
$this->customerFactory = $customerFactory;
400400
$this->eventManager = $eventManager;

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class AccountManagementTest extends \PHPUnit\Framework\TestCase
142142
*/
143143
private $saveHandler;
144144

145+
/**
146+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\AddressRegistry
147+
*/
148+
private $addressRegistryMock;
149+
145150
/**
146151
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
147152
*/
@@ -176,6 +181,7 @@ protected function setUp()
176181
$this->dateTime = $this->createMock(\Magento\Framework\Stdlib\DateTime::class);
177182
$this->customer = $this->createMock(\Magento\Customer\Model\Customer::class);
178183
$this->objectFactory = $this->createMock(\Magento\Framework\DataObjectFactory::class);
184+
$this->addressRegistryMock = $this->createMock(\Magento\Customer\Model\AddressRegistry::class);
179185
$this->extensibleDataObjectConverter = $this->createMock(
180186
\Magento\Framework\Api\ExtensibleDataObjectConverter::class
181187
);
@@ -239,6 +245,7 @@ protected function setUp()
239245
'sessionManager' => $this->sessionManager,
240246
'saveHandler' => $this->saveHandler,
241247
'visitorCollectionFactory' => $this->visitorCollectionFactory,
248+
'addressRegistry' => $this->addressRegistryMock,
242249
]
243250
);
244251
$this->objectManagerHelper->setBackwardCompatibleProperty(
@@ -1071,6 +1078,7 @@ public function testSendPasswordReminderEmail()
10711078
protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash)
10721079
{
10731080
$websiteId = 1;
1081+
$addressId = 5;
10741082

10751083
$datetime = $this->prepareDateTimeFactory();
10761084

@@ -1088,6 +1096,17 @@ protected function prepareInitiatePasswordReset($email, $templateIdentifier, $se
10881096
->method('getStore')
10891097
->willReturn($this->store);
10901098

1099+
/** @var \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject $addressModel */
1100+
$addressModel = $this->getMockBuilder(\Magento\Customer\Model\Address::class)->disableOriginalConstructor()
1101+
->setMethods(['setShouldIgnoreValidation'])->getMock();
1102+
1103+
/** @var \Magento\Customer\Api\Data\AddressInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
1104+
$address = $this->createMock(\Magento\Customer\Api\Data\AddressInterface::class);
1105+
$address->expects($this->once())
1106+
->method('getId')
1107+
->willReturn($addressId);
1108+
1109+
/** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
10911110
$customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
10921111
->getMock();
10931112
$customer->expects($this->any())
@@ -1099,6 +1118,20 @@ protected function prepareInitiatePasswordReset($email, $templateIdentifier, $se
10991118
$customer->expects($this->any())
11001119
->method('getStoreId')
11011120
->willReturn($storeId);
1121+
$customer->expects($this->any())
1122+
->method('getAddresses')
1123+
->willReturn([$address]);
1124+
1125+
$this->customerRepository->expects($this->once())
1126+
->method('get')
1127+
->willReturn($customer);
1128+
$this->addressRegistryMock->expects($this->once())
1129+
->method('retrieve')
1130+
->with($addressId)
1131+
->willReturn($addressModel);
1132+
$addressModel->expects($this->once())
1133+
->method('setShouldIgnoreValidation')
1134+
->with(true);
11021135

11031136
$this->customerRepository->expects($this->once())
11041137
->method('get')

0 commit comments

Comments
 (0)