Esempio n. 1
0
 /**
  * Invoke InvoiceCommentsList service
  *
  * @param int $id
  * @return \Magento\Sales\Service\V1\Data\CommentSearchResults
  */
 public function invoke($id)
 {
     $this->criteriaBuilder->addFilter(['eq' => $this->filterBuilder->setField('parent_id')->setValue($id)->create()]);
     $criteria = $this->criteriaBuilder->create();
     $comments = [];
     foreach ($this->commentRepository->find($criteria) as $comment) {
         $comments[] = $this->commentMapper->extractDto($comment);
     }
     return $this->searchResultsBuilder->setItems($comments)->setSearchCriteria($criteria)->setTotalCount(count($comments))->create();
 }
Esempio n. 2
0
 /**
  * test invoice comments list service
  */
 public function testInvoke()
 {
     $invoiceId = 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($invoiceId))->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->commentRepositoryMock->expects($this->once())->method('find')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnValue([$this->invoiceCommentMock]));
     $this->commentMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->invoiceCommentMock))->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->invoiceCommentsList->invoke($invoiceId));
 }