Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
OrderInvoiceCreateTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Bundle\Api;
7 
12 {
13  const SERVICE_READ_NAME = 'salesInvoiceOrderV1';
14  const SERVICE_VERSION = 'V1';
15 
19  private $objectManager;
20 
24  private $invoiceRepository;
25 
31  protected function setUp()
32  {
34  $this->invoiceRepository = $this->objectManager->get(
35  \Magento\Sales\Api\InvoiceRepositoryInterface::class
36  );
37  }
38 
45  public function testInvoiceWithSimpleAndBundleCreate()
46  {
48  $existingOrder = $this->objectManager->create(\Magento\Sales\Api\Data\OrderInterface::class)
49  ->loadByIncrementId('100000001');
50 
51  $serviceInfo = [
52  'rest' => [
53  'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
55  ],
56  'soap' => [
57  'service' => self::SERVICE_READ_NAME,
58  'serviceVersion' => self::SERVICE_VERSION,
59  'operation' => self::SERVICE_READ_NAME . 'execute',
60  ],
61  ];
62 
63  $requestData = [
64  'orderId' => $existingOrder->getId(),
65  'items' => [],
66  'comment' => [
67  'comment' => 'Test Comment',
68  'is_visible_on_front' => 1,
69  ],
70  ];
71  $grantTotal = 0;
72  foreach ($existingOrder->getAllItems() as $item) {
73  $requestData['items'] = [];
74  $requestData['items'][] = [
75  'order_item_id' => $item->getItemId(),
76  'qty' => $item->getQtyOrdered(),
77  ];
78  $result = $this->_webApiCall($serviceInfo, $requestData);
79  $this->assertNotEmpty($result);
80  try {
81  $invoice = $this->invoiceRepository->get($result);
82  $grantTotal += $invoice->getGrandTotal();
83  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
84  $this->fail('Failed asserting that Invoice was created');
85  }
86  }
87  $this->assertNotEquals(
88  $existingOrder->getGrandTotal(),
89  $grantTotal,
90  'Failed asserting that invoice is correct.'
91  );
92  }
93 
100  public function testInvoiceWithBundleCreate()
101  {
103  $existingOrder = $this->objectManager->create(\Magento\Sales\Api\Data\OrderInterface::class)
104  ->loadByIncrementId('100000001');
105 
106  $serviceInfo = [
107  'rest' => [
108  'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
110  ],
111  'soap' => [
112  'service' => self::SERVICE_READ_NAME,
113  'serviceVersion' => self::SERVICE_VERSION,
114  'operation' => self::SERVICE_READ_NAME . 'execute',
115  ],
116  ];
117 
118  $requestData = [
119  'orderId' => $existingOrder->getId(),
120  'items' => [],
121  'comment' => [
122  'comment' => 'Test Comment',
123  'is_visible_on_front' => 1,
124  ],
125  ];
126 
128  foreach ($existingOrder->getAllItems() as $item) {
129  $requestData['items'][] = [
130  'order_item_id' => $item->getItemId(),
131  'qty' => $item->getQtyOrdered(),
132  ];
133  }
134  $result = $this->_webApiCall($serviceInfo, $requestData);
135  $this->assertNotEmpty($result);
136  $invoice = $this->invoiceRepository->get($result);
137  $this->assertNotEquals(
138  $existingOrder->getGrandTotal(),
139  $invoice->getGrandTotal(),
140  'Failed asserting that invoice is correct.'
141  );
142  }
143 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$invoice