/**
  * test SaveAuth
  */
 public function testSaveAuth()
 {
     $customerId = 1;
     $customerSecureMock = $this->getMock(\Magento\Customer\Model\Data\CustomerSecure::class, [], [], '', false);
     $dbAdapter = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class, [], [], '', false);
     $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->willReturn($customerSecureMock);
     $customerSecureMock->expects($this->exactly(3))->method('getData')->willReturn(1);
     $this->customerResourceModel->expects($this->any())->method('getConnection')->willReturn($dbAdapter);
     $this->customerResourceModel->expects($this->any())->method('getTable')->willReturn('customer_entity');
     $dbAdapter->expects($this->any())->method('update')->with('customer_entity', ['failures_num' => 1, 'first_failure' => 1, 'lock_expires' => 1]);
     $dbAdapter->expects($this->any())->method('quoteInto')->with('entity_id = ?', $customerId);
     $this->model->saveAuth($customerId);
 }
 protected function setUp()
 {
     $this->_website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $this->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->_attribute = $this->getMock('Magento\\Eav\\Model\\Attribute', [], [], '', false);
     $this->_storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $this->_storetMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $this->_scopeConfigMock = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->_transportBuilderMock = $this->getMock('\\Magento\\Framework\\Mail\\Template\\TransportBuilder', [], [], '', false);
     $this->_transportMock = $this->getMock('Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $this->attributeFactoryMock = $this->getMock('Magento\\Customer\\Model\\AttributeFactory', ['create'], [], '', false);
     $this->attributeCustomerMock = $this->getMock('Magento\\Customer\\Model\\Attribute', [], [], '', false);
     $this->resourceMock = $this->getMock('\\Magento\\Customer\\Model\\ResourceModel\\Customer', ['getIdFieldName'], [], '', false, false);
     $this->resourceMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id'));
     $this->registryMock = $this->getMock('Magento\\Framework\\Registry', ['registry'], [], '', false);
     $this->_encryptor = $this->getMock('Magento\\Framework\\Encryption\\EncryptorInterface');
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_model = $helper->getObject('Magento\\Customer\\Model\\Customer', ['storeManager' => $this->_storeManager, 'config' => $this->_config, 'transportBuilder' => $this->_transportBuilderMock, 'scopeConfig' => $this->_scopeConfigMock, 'encryptor' => $this->_encryptor, 'attributeFactory' => $this->attributeFactoryMock, 'registry' => $this->registryMock, 'resource' => $this->resourceMock]);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSaveWithPasswordHash()
 {
     $customerId = 1;
     $storeId = 2;
     $passwordHash = 'ukfa4sdfa56s5df02asdf4rt';
     $this->prepareMocksForValidation(true);
     $region = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\RegionInterface', [], '', false);
     $address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, false, true, ['setCustomerId', 'setRegion', 'getRegion', 'getId']);
     $address2 = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, false, true, ['setCustomerId', 'setRegion', 'getRegion', 'getId']);
     $customerModel = $this->getMock('Magento\\Customer\\Model\\Customer', ['getId', 'setId', 'setStoreId', 'getStoreId', 'getAttributeSetId', 'setAttributeSetId', 'setRpToken', 'setRpTokenCreatedAt', 'getDataModel', 'setPasswordHash'], [], '', false);
     $customerAttributesMetaData = $this->getMockForAbstractClass('Magento\\Framework\\Api\\CustomAttributesDataInterface', [], '', false, false, true, ['getId', 'getEmail', 'getWebsiteId', 'getAddresses', 'setAddresses']);
     $this->customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieve')->with($customerId)->willReturn($customerModel);
     $customerModel->expects($this->atLeastOnce())->method('getDataModel')->willReturn($this->customer);
     $this->imageProcessor->expects($this->once())->method('save')->with($this->customer, CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $this->customer)->willReturn($customerAttributesMetaData);
     $address->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
     $address->expects($this->once())->method('getRegion')->willReturn($region);
     $address->expects($this->atLeastOnce())->method('getId')->willReturn(7);
     $address->expects($this->once())->method('setRegion')->with($region);
     $customerAttributesMetaData->expects($this->any())->method('getAddresses')->willReturn([$address]);
     $customerAttributesMetaData->expects($this->at(1))->method('setAddresses')->with([]);
     $customerAttributesMetaData->expects($this->at(2))->method('setAddresses')->with([$address]);
     $this->extensibleDataObjectConverter->expects($this->once())->method('toNestedArray')->with($customerAttributesMetaData, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn(['customerData']);
     $this->customerFactory->expects($this->once())->method('create')->with(['data' => ['customerData']])->willReturn($customerModel);
     $customerModel->expects($this->once())->method('getStoreId')->willReturn(null);
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->once())->method('getId')->willReturn($storeId);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $customerModel->expects($this->once())->method('setStoreId')->with($storeId);
     $customerModel->expects($this->once())->method('setId')->with(null);
     $customerModel->expects($this->once())->method('getAttributeSetId')->willReturn(null);
     $customerModel->expects($this->once())->method('setAttributeSetId')->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
     $customerModel->expects($this->once())->method('setPasswordHash')->with($passwordHash);
     $customerModel->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $this->customerResourceModel->expects($this->once())->method('save')->with($customerModel);
     $this->customerRegistry->expects($this->once())->method('push')->with($customerModel);
     $this->customer->expects($this->any())->method('getAddresses')->willReturn([$address, $address2]);
     $this->addressRepository->expects($this->once())->method('save')->with($address);
     $customerAttributesMetaData->expects($this->once())->method('getEmail')->willReturn('*****@*****.**');
     $customerAttributesMetaData->expects($this->once())->method('getWebsiteId')->willReturn(2);
     $this->customerRegistry->expects($this->once())->method('retrieveByEmail')->with('*****@*****.**', 2)->willReturn($customerModel);
     $this->eventManager->expects($this->once())->method('dispatch')->with('customer_save_after_data_object', ['customer_data_object' => $this->customer, 'orig_customer_data_object' => $customerAttributesMetaData]);
     $this->model->save($this->customer, $passwordHash);
 }
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage error occurred
  */
 public function testAroundSaveRollBack()
 {
     $this->resourceMock->expects($this->once())->method('beginTransaction');
     $this->resourceMock->expects($this->once())->method('rollBack');
     $this->model->aroundSave($this->subjectMock, $this->rollbackClosureMock, $this->customerMock, $this->passwordHash);
 }