Skip to content

Commit

Permalink
Updated the unit test, fix and additional issue #18170
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-ch committed Sep 22, 2018
1 parent 030b223 commit 54b6382
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function __construct(
SessionManagerInterface $sessionManager = null,
SaveHandlerInterface $saveHandler = null,
CollectionFactory $visitorCollectionFactory = null,
AddressRegistry $addressRegistry
AddressRegistry $addressRegistry = null
) {
$this->customerFactory = $customerFactory;
$this->eventManager = $eventManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class AccountManagementTest extends \PHPUnit\Framework\TestCase
*/
private $saveHandler;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\AddressRegistry
*/
private $addressRegistryMock;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down Expand Up @@ -176,6 +181,7 @@ protected function setUp()
$this->dateTime = $this->createMock(\Magento\Framework\Stdlib\DateTime::class);
$this->customer = $this->createMock(\Magento\Customer\Model\Customer::class);
$this->objectFactory = $this->createMock(\Magento\Framework\DataObjectFactory::class);
$this->addressRegistryMock = $this->createMock(\Magento\Customer\Model\AddressRegistry::class);
$this->extensibleDataObjectConverter = $this->createMock(
\Magento\Framework\Api\ExtensibleDataObjectConverter::class
);
Expand Down Expand Up @@ -239,6 +245,7 @@ protected function setUp()
'sessionManager' => $this->sessionManager,
'saveHandler' => $this->saveHandler,
'visitorCollectionFactory' => $this->visitorCollectionFactory,
'addressRegistry' => $this->addressRegistryMock,
]
);
$this->objectManagerHelper->setBackwardCompatibleProperty(
Expand Down Expand Up @@ -1071,6 +1078,7 @@ public function testSendPasswordReminderEmail()
protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash)
{
$websiteId = 1;
$addressId = 5;

$datetime = $this->prepareDateTimeFactory();

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

/** @var \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject $addressModel */
$addressModel = $this->getMockBuilder(\Magento\Customer\Model\Address::class)->disableOriginalConstructor()
->setMethods(['setShouldIgnoreValidation'])->getMock();

/** @var \Magento\Customer\Api\Data\AddressInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
$address = $this->createMock(\Magento\Customer\Api\Data\AddressInterface::class);
$address->expects($this->once())
->method('getId')
->willReturn($addressId);

/** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
$customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
->getMock();
$customer->expects($this->any())
Expand All @@ -1099,6 +1118,20 @@ protected function prepareInitiatePasswordReset($email, $templateIdentifier, $se
$customer->expects($this->any())
->method('getStoreId')
->willReturn($storeId);
$customer->expects($this->any())
->method('getAddresses')
->willReturn([$address]);

$this->customerRepository->expects($this->once())
->method('get')
->willReturn($customer);
$this->addressRegistryMock->expects($this->once())
->method('retrieve')
->with($addressId)
->willReturn($addressModel);
$addressModel->expects($this->once())
->method('setShouldIgnoreValidation')
->with(true);

$this->customerRepository->expects($this->once())
->method('get')
Expand Down

0 comments on commit 54b6382

Please sign in to comment.