/**
  * Resolve customers data based on ids quote table.
  *
  * @return void
  */
 public function resolveCustomerNames()
 {
     $select = $this->customerResource->getConnection()->select();
     $customerName = $this->customerResource->getConnection()->getConcatSql(['firstname', 'lastname'], ' ');
     $select->from(['customer' => $this->customerResource->getTable('customer_entity')], ['email']);
     $select->columns(['customer_name' => $customerName]);
     $select->where('customer.entity_id IN (?)', array_column($this->getData(), 'customer_id'));
     $customersData = $this->customerResource->getConnection()->fetchAll($select);
     foreach ($this->getItems() as $item) {
         $item->setData(array_merge($item->getData(), current($customersData)));
         next($customersData);
     }
 }
 /**
  * Test _saveCustomerDefaults
  *
  * @magentoDataFixture Magento/Customer/_files/import_export/customer_with_addresses.php
  */
 public function testSaveCustomerDefaults()
 {
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     // get not default address
     $customers = $objectManager->get('Magento\\Framework\\Registry')->registry($this->_fixtureKey);
     /** @var $notDefaultAddress \Magento\Customer\Model\Address */
     $notDefaultAddress = null;
     /** @var $addressCustomer \Magento\Customer\Model\Customer */
     $addressCustomer = null;
     /** @var $customer \Magento\Customer\Model\Customer */
     foreach ($customers as $customer) {
         /** @var $address \Magento\Customer\Model\Address */
         foreach ($customer->getAddressesCollection() as $address) {
             if (!$customer->getDefaultBillingAddress() && !$customer->getDefaultShippingAddress()) {
                 $notDefaultAddress = $address;
                 $addressCustomer = $customer;
                 break;
             }
             if ($notDefaultAddress) {
                 break;
             }
         }
     }
     $this->assertNotNull($notDefaultAddress, 'Not default address must exists.');
     $this->assertNotNull($addressCustomer, 'Not default address customer must exists.');
     $addressId = $notDefaultAddress->getId();
     $customerId = $addressCustomer->getId();
     // set customer defaults
     $defaults = [$this->customerResource->getTable('customer_entity') => [$customerId => ['default_billing' => $addressId, 'default_shipping' => $addressId]]];
     // invoke _saveCustomerDefaults
     $saveDefaults = new \ReflectionMethod($this->_testClassName, '_saveCustomerDefaults');
     $saveDefaults->setAccessible(true);
     $saveDefaults->invoke($this->_entityAdapter, $defaults);
     // check DB
     /** @var $testCustomer \Magento\Customer\Model\Customer */
     $testCustomer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Customer');
     $testCustomer->load($customerId);
     $this->assertEquals($customerId, $testCustomer->getId(), 'Customer must exists.');
     $this->assertNotNull($testCustomer->getDefaultBillingAddress(), 'Default billing address must exists.');
     $this->assertNotNull($testCustomer->getDefaultShippingAddress(), 'Default shipping address must exists.');
     $this->assertEquals($addressId, $testCustomer->getDefaultBillingAddress()->getId(), 'Incorrect default billing address.');
     $this->assertEquals($addressId, $testCustomer->getDefaultShippingAddress()->getId(), 'Incorrect default shipping address.');
 }
 /**
  * Reset Authentication data for customer.
  *
  * @param int $customerId
  * @return $this
  */
 public function saveAuth($customerId)
 {
     $customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
     $this->customerResourceModel->getConnection()->update($this->customerResourceModel->getTable('customer_entity'), ['failures_num' => $customerSecure->getData('failures_num'), 'first_failure' => $customerSecure->getData('first_failure'), 'lock_expires' => $customerSecure->getData('lock_expires')], $this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customerId));
     return $this;
 }