public function testAssignCustomer() { $cartId = 220; $customerId = 455; $storeId = 5; $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', ['getCustomerId', 'setCustomer', 'setCustomerIsGuest'], [], '', false); $customerMock = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->willReturn($quoteMock); $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customerMock); $customerModelMock = $this->getMock('\\Magento\\Customer\\Model\\Customer', ['load', 'getSharedStoreIds'], [], '', false); $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customerModelMock); $customerModelMock->expects($this->once())->method('load')->with($customerId)->willReturnSelf(); $customerModelMock->expects($this->once())->method('getSharedStoreIds')->willReturn([$storeId, 'some store value']); $quoteMock->expects($this->once())->method('getCustomerId')->willReturn(null); $this->quoteRepositoryMock->expects($this->once())->method('getForCustomer')->with($customerId)->willThrowException(new NoSuchEntityException()); $quoteMock->expects($this->once())->method('setCustomer')->with($customerMock); $quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(0); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $this->model->assignCustomer($cartId, $customerId, $storeId); }