/** * Invoke OrderList service * * @param \Magento\Framework\Service\V1\Data\SearchCriteria $searchCriteria * @return \Magento\Sales\Service\V1\Data\OrderSearchResults */ public function invoke(SearchCriteria $searchCriteria) { $orders = []; foreach ($this->orderRepository->find($searchCriteria) as $order) { $orders[] = $this->orderMapper->extractDto($order); } return $this->searchResultsBuilder->setItems($orders)->setTotalCount(count($orders))->setSearchCriteria($searchCriteria)->create(); }
/** * test order list service */ public function testInvoke() { $this->orderRepositoryMock->expects($this->once())->method('find')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnValue([$this->orderMock])); $this->orderMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderMock))->will($this->returnValue($this->dataObjectMock)); $this->searchResultsBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo([$this->dataObjectMock]))->will($this->returnSelf()); $this->searchResultsBuilderMock->expects($this->once())->method('setTotalCount')->with($this->equalTo(1))->will($this->returnSelf()); $this->searchResultsBuilderMock->expects($this->once())->method('setSearchCriteria')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnSelf()); $this->searchResultsBuilderMock->expects($this->once())->method('create')->will($this->returnValue('expected-result')); $this->assertEquals('expected-result', $this->orderList->invoke($this->searchCriteriaMock)); }
/** * test order mapper */ public function testInvoke() { $this->orderMock->expects($this->once())->method('getData')->will($this->returnValue(['field-1' => 'value-1'])); $this->orderMock->expects($this->once())->method('getItemsCollection')->will($this->returnValue([$this->orderItemMock])); $this->orderMock->expects($this->once())->method('getPaymentsCollection')->will($this->returnValue([$this->orderPaymentMock])); $this->orderMock->expects($this->exactly(2))->method('getBillingAddress')->will($this->returnValue($this->orderAddressMock)); $this->orderMock->expects($this->exactly(2))->method('getShippingAddress')->will($this->returnValue($this->orderAddressMock)); $this->orderBuilderMock->expects($this->once())->method('populateWithArray')->with($this->equalTo(['field-1' => 'value-1']))->will($this->returnSelf()); $this->orderItemMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderItemMock))->will($this->returnValue('item-1')); $this->orderPaymentMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderPaymentMock))->will($this->returnValue('payment-1')); $this->orderAddressMapperMock->expects($this->exactly(2))->method('extractDto')->with($this->equalTo($this->orderAddressMock))->will($this->returnValue('address-1')); $this->orderBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo(['item-1']))->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setPayments')->with($this->equalTo(['payment-1']))->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setBillingAddress')->with($this->equalTo('address-1'))->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setShippingAddress')->with($this->equalTo('address-1'))->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('create')->will($this->returnValue('data-object-with-order')); $this->assertEquals('data-object-with-order', $this->orderMapper->extractDto($this->orderMock)); }
/** * Invoke getOrder service * * @param int $id * @return \Magento\Sales\Service\V1\Data\Order * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function invoke($id) { return $this->orderMapper->extractDto($this->orderRepository->get($id)); }
/** * test order list service */ public function testInvoke() { $this->orderRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->orderMock)); $this->orderMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderMock))->will($this->returnValue($this->dataObjectMock)); $this->assertEquals($this->dataObjectMock, $this->orderGet->invoke(1)); }