Пример #1
0
 /**
  * TODO: Cover with unit tests the other methods in the repository
  * test GetList
  */
 public function testGetList()
 {
     $fieldName = 'field';
     $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $collectionMock = $this->getMock('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection', [], [], '', false);
     $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $filterGroupFilterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false);
     $sortOrderMock = $this->getMock('\\Magento\\Framework\\Api\\SortOrder', [], [], '', false);
     $itemsMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $extensionAttributes = $this->getMock('\\Magento\\Sales\\Api\\Data\\OrderExtension', ['getShippingAssignments'], [], '', false);
     $shippingAssignmentBuilder = $this->getMock('\\Magento\\Sales\\Model\\Order\\ShippingAssignmentBuilder', [], [], '', false);
     $itemsMock->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
     $extensionAttributes->expects($this->any())->method('getShippingAssignments')->willReturn($shippingAssignmentBuilder);
     $this->searchResultFactory->expects($this->once())->method('create')->willReturn($collectionMock);
     $searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]);
     $filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterGroupFilterMock]);
     $filterGroupFilterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('eq');
     $filterGroupFilterMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName);
     $filterGroupFilterMock->expects($this->once())->method('getValue')->willReturn('value');
     $sortOrderMock->expects($this->once())->method('getDirection');
     $searchCriteriaMock->expects($this->once())->method('getSortOrders')->willReturn([$sortOrderMock]);
     $sortOrderMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName);
     $collectionMock->expects($this->once())->method('addFieldToFilter')->willReturn(SortOrder::SORT_ASC);
     $collectionMock->expects($this->once())->method('addOrder')->with($fieldName, 'DESC');
     $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->willReturn(4);
     $collectionMock->expects($this->once())->method('setCurPage')->with(4);
     $searchCriteriaMock->expects($this->once())->method('getPageSize')->willReturn(42);
     $collectionMock->expects($this->once())->method('setPageSize')->with(42);
     $collectionMock->expects($this->once())->method('getItems')->willReturn([$itemsMock]);
     $this->assertEquals($collectionMock, $this->model->getList($searchCriteriaMock));
 }
Пример #2
0
 /**
  * Invoke service
  *
  * @param int $id
  * @param \Magento\Sales\Service\V1\Data\OrderStatusHistory $statusHistory
  * @return bool
  */
 public function invoke($id, OrderStatusHistory $statusHistory)
 {
     $order = $this->orderRepository->get($id);
     $order->addStatusHistory($this->historyConverter->getModel($statusHistory));
     $order->save();
     return true;
 }
Пример #3
0
 /**
  * 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();
 }
Пример #4
0
 /**
  * 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));
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'save');
     if (!$pluginInfo) {
         return parent::save($entity);
     } else {
         return $this->___callPlugins('save', func_get_args(), $pluginInfo);
     }
 }
Пример #6
0
 /**
  * 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));
 }
Пример #7
0
 /**
  * test order hold service
  */
 public function testInvoke()
 {
     $this->orderRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->orderMock));
     $this->orderMock->expects($this->once())->method('hold')->will($this->returnSelf());
     $this->assertTrue($this->orderHold->invoke(1));
 }
Пример #8
0
 /**
  * Invoke orderHold service
  *
  * @param int $id
  * @return bool
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function invoke($id)
 {
     return (bool) $this->orderRepository->get($id)->hold();
 }
Пример #9
0
 /**
  * Invoke notifyUser service
  *
  * @param int $id
  * @return bool
  */
 public function invoke($id)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = $this->orderRepository->get($id);
     return $this->notifier->notify($order);
 }
Пример #10
0
 /**
  * Retrieve order status by id
  *
  * @param int $id
  * @return string
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function invoke($id)
 {
     return $this->orderRepository->get($id)->getStatus();
 }
Пример #11
0
 public function testGetOrderNull()
 {
     $payment = $this->initPayment();
     $this->orderRepository->expects($this->never())->method('get');
     $this->assertNull($payment->getOrder());
 }
Пример #12
0
 /**
  * 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));
 }