Example #1
0
 /**
  * Invoke OrderCommentsList service
  *
  * @param int $id
  * @return \Magento\Sales\Service\V1\Data\OrderStatusHistorySearchResults
  */
 public function invoke($id)
 {
     $this->criteriaBuilder->addFilter(['eq' => $this->filterBuilder->setField('parent_id')->setValue($id)->create()]);
     $criteria = $this->criteriaBuilder->create();
     $comments = [];
     foreach ($this->historyRepository->find($criteria) as $comment) {
         $comments[] = $this->historyMapper->extractDto($comment);
     }
     return $this->searchResultsBuilder->setItems($comments)->setSearchCriteria($criteria)->setTotalCount(count($comments))->create();
 }
Example #2
0
 /**
  * test order comments list service
  */
 public function testInvoke()
 {
     $orderId = 1;
     $this->filterBuilderMock->expects($this->once())->method('setField')->with($this->equalTo('parent_id'))->will($this->returnSelf());
     $this->filterBuilderMock->expects($this->once())->method('setValue')->with($this->equalTo($orderId))->will($this->returnSelf());
     $this->filterBuilderMock->expects($this->once())->method('create')->will($this->returnValue('filter'));
     $this->criteriaBuilderMock->expects($this->once())->method('addFilter')->with($this->equalTo(['eq' => 'filter']))->will($this->returnSelf());
     $this->criteriaBuilderMock->expects($this->once())->method('create')->will($this->returnValue($this->searchCriteriaMock));
     $this->historyRepositoryMock->expects($this->once())->method('find')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnValue([$this->orderCommentMock]));
     $this->historyMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderCommentMock))->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->orderCommentsList->invoke($orderId));
 }