public function testCreateCustomerFromModel() { $customerModelMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->setMethods(array('getId', 'getFirstname', 'getLastname', 'getEmail', 'getAttributes', 'getData', '__wakeup'))->getMock(); $attributeModelMock = $this->getMockBuilder('\\Magento\\Customer\\Model\\Attribute')->disableOriginalConstructor()->getMock(); $attributeModelMock->expects($this->at(0))->method('getAttributeCode')->will($this->returnValue('attribute_code')); $attributeModelMock->expects($this->at(1))->method('getAttributeCode')->will($this->returnValue('attribute_code2')); $attributeModelMock->expects($this->at(2))->method('getAttributeCode')->will($this->returnValue('attribute_code3')); $this->_mockReturnValue($customerModelMock, array('getId' => 1, 'getFirstname' => 'Tess', 'getLastname' => 'Tester', 'getEmail' => '*****@*****.**', 'getAttributes' => array($attributeModelMock, $attributeModelMock, $attributeModelMock))); $map = array(array('attribute_code', null, 'attributeValue'), array('attribute_code2', null, 'attributeValue2'), array('attribute_code3', null, null)); $customerModelMock->expects($this->any())->method('getData')->will($this->returnValueMap($map)); $customerBuilder = $this->_objectManager->getObject('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder', ['metadataService' => $this->_metadataService]); $customerFactory = $this->getMockBuilder('Magento\\Customer\\Model\\CustomerFactory')->disableOriginalConstructor()->getMock(); $converter = new Converter($customerBuilder, $customerFactory, $this->storeManagerMock); $customerDataObject = $converter->createCustomerFromModel($customerModelMock); $customerBuilder = $this->_objectManager->getObject('Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder', ['metadataService' => $this->_metadataService]); $customerData = array('firstname' => 'Tess', 'email' => '*****@*****.**', 'lastname' => 'Tester', 'id' => 1, 'attribute_code' => 'attributeValue', 'attribute_code2' => 'attributeValue2'); // There will be no attribute_code3: it has a value of null, so the converter will drop it $customerBuilder->populateWithArray($customerData); $expectedCustomerData = $customerBuilder->create(); $this->assertEquals($expectedCustomerData, $customerDataObject); }
/** * Returns Customer data object with the customer information * * @return CustomerData */ public function getCustomerDataObject() { /* TODO refactor this after all usages of the setCustomer is refactored */ return $this->_converter->createCustomerFromModel($this->getCustomer()); }
/** * Retrieve customer data object * * @return CustomerDataObject */ public function getCustomerData() { /* @TODO: remove this code in favor of setCustomerData usage MAGETWO-19930 */ $customerModel = $this->getCustomer(); return $this->_converter->createCustomerFromModel($customerModel); }
/** * {@inheritDoc} */ public function getCustomerByEmail($customerEmail, $websiteId = null) { $customerModel = $this->customerRegistry->retrieveByEmail($customerEmail, $websiteId); return $this->converter->createCustomerFromModel($customerModel); }