1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Service\V1;
use Magento\TestFramework\TestCase\WebapiAbstract;
/**
* Class InvoiceGetTest
*/
class InvoiceGetTest extends WebapiAbstract
{
const RESOURCE_PATH = '/V1/invoices';
const SERVICE_READ_NAME = 'salesInvoiceRepositoryV1';
const SERVICE_VERSION = 'V1';
/**
* @magentoApiDataFixture Magento/Sales/_files/invoice.php
*/
public function testInvoiceGet()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Sales\Model\Order\Invoice $invoice */
$invoiceCollection = $objectManager->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class);
$invoice = $invoiceCollection->getFirstItem();
$expectedInvoiceData = [
'grand_total' => '100.0000',
'subtotal' => '100.0000',
'increment_id' => $invoice->getIncrementId(),
];
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '/' . $invoice->getId(),
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_READ_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_READ_NAME . 'get',
],
];
$result = $this->_webApiCall($serviceInfo, ['id' => $invoice->getId()]);
foreach ($expectedInvoiceData as $field => $value) {
$this->assertArrayHasKey($field, $result);
$this->assertEquals($value, $result[$field]);
}
//check that nullable fields were marked as optional and were not sent
foreach ($result as $value) {
$this->assertNotNull($value);
}
}
}