/**
  * @magentoAppArea frontend
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @expectedException \Magento\Framework\Exception\StateException
  */
 public function testUpdateCustomerDetailsByEmailWithException()
 {
     $customerId = 1;
     $customerDetails = $this->_customerAccountService->getCustomerDetails($customerId);
     $email = $customerDetails->getCustomer()->getEmail();
     $customerData = array_merge($customerDetails->getCustomer()->__toArray(), ['firstname' => 'fname', 'id' => 1234567]);
     $this->_customerBuilder->populateWithArray($customerData);
     $this->_customerDetailsBuilder->setCustomer($this->_customerBuilder->create())->setAddresses([]);
     $this->_customerAccountService->updateCustomerDetailsByEmail($email, $this->_customerDetailsBuilder->create());
 }
 public function connectByFacebookId($facebookId, \stdClass $token, $customerId)
 {
     $customerDetailsObject = $this->_customerAccountService->getCustomerDetails($customerId);
     /* @var $customerDetailsObject \Magento\Customer\Service\V1\Data\CustomerDetails */
     $customerDataObject = $customerDetailsObject->getCustomer();
     /* @var $customerDetailsObject \Magento\Customer\Service\V1\Data\Customer */
     // Merge old and new data
     $customerDetailsArray = array_merge($customerDataObject->__toArray(), array('custom_attributes' => array(array(\Magento\Framework\Service\Data\AttributeValue::ATTRIBUTE_CODE => 'inchoo_socialconnect_fid', \Magento\Framework\Service\Data\AttributeValue::VALUE => $facebookId), array(\Magento\Framework\Service\Data\AttributeValue::ATTRIBUTE_CODE => 'inchoo_socialconnect_ftoken', \Magento\Framework\Service\Data\AttributeValue::VALUE => serialize($token)))));
     // Pass result to customerBuilder
     $this->_customerBuilder->populateWithArray($customerDetailsArray);
     // Pass result to customerDetailsBuilder
     $this->_customerDetailsBuilder->setCustomer($this->_customerBuilder->create());
     // Update customer
     $this->_customerAccountService->updateCustomer($customerId, $this->_customerDetailsBuilder->create());
     // Set customer as logged in
     $this->_customerSession->setCustomerDataAsLoggedIn($customerDataObject);
 }