Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvoiceCommentsListTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
15  const SERVICE_NAME = 'salesInvoiceManagementV1';
16 
17  const SERVICE_VERSION = 'V1';
18 
22  public function testInvoiceCommentsList()
23  {
24  $comment = 'Test comment';
26 
28  $invoiceCollection = $objectManager->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class);
29  $invoice = $invoiceCollection->getFirstItem();
30  $invoiceComment = $objectManager->get(\Magento\Sales\Model\Order\Invoice\Comment::class);
31  $invoiceComment->setComment($comment);
32  $invoiceComment->setParentId($invoice->getId());
33  $invoiceComment->save();
34 
35  $serviceInfo = [
36  'rest' => [
37  'resourcePath' => '/V1/invoices/' . $invoice->getId() . '/comments',
39  ],
40  'soap' => [
41  'service' => self::SERVICE_NAME,
42  'serviceVersion' => self::SERVICE_VERSION,
43  'operation' => self::SERVICE_NAME . 'getCommentsList',
44  ],
45  ];
46  $requestData = ['id' => $invoice->getId()];
47  // TODO Test fails, due to the inability of the framework API to handle data collection
48  $result = $this->_webApiCall($serviceInfo, $requestData);
49  foreach ($result['items'] as $item) {
51  $invoiceHistoryStatus = $objectManager->get(\Magento\Sales\Model\Order\Invoice\Comment::class)
52  ->load($item['entity_id']);
53  $this->assertEquals($invoiceHistoryStatus->getComment(), $item['comment']);
54  }
55  }
56 }
$objectManager
Definition: bootstrap.php:17
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$invoice