Exemplo n.º 1
0
 public function testOrder()
 {
     $cartId = 123;
     $quoteService = $this->getMock('Magento\\Sales\\Model\\Service\\Quote', [], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteServiceFactory->expects($this->once())->method('create')->with(['quote' => $this->quoteMock])->will($this->returnValue($quoteService));
     $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $orderMock->expects($this->any())->method('getId')->will($this->returnValue(5));
     $quoteService->expects($this->once())->method('submitOrderWithDataObject')->will($this->returnValue($orderMock));
     $this->assertEquals(5, $this->service->order($cartId));
 }
 public function testAssignCustomer()
 {
     $cartId = 956;
     $customerId = 125;
     $storeId = 12;
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->quoteFactoryMock->expects($this->at(0))->method('create')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('load')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getId')->will($this->returnValue($cartId));
     $this->quoteMock->expects($this->once())->method('getStoreId')->will($this->returnValue($storeId));
     $customerMock = $this->getMock('\\Magento\\Customer\\Model\\Customer', [], [], '', false);
     $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->will($this->returnValue($customerMock));
     $customerQuoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false);
     $customerQuoteMock->expects($this->once())->method('loadByCustomer')->with($customerMock)->will($this->returnSelf());
     $this->quoteFactoryMock->expects($this->at(1))->method('create')->will($this->returnValue($customerQuoteMock));
     $customerMock->expects($this->once())->method('getSharedStoreIds')->will($this->returnValue([$storeId]));
     $this->quoteMock->expects($this->once())->method('getCustomerId')->will($this->returnValue(false));
     $this->quoteMock->expects($this->once())->method('setCustomer')->with($customerMock)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(0)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('save')->will($this->returnValue($this->quoteMock));
     $this->assertTrue($this->service->assignCustomer($cartId, $customerId));
 }