InvoiceGetTest.php 1.9 KB

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