UpdateTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryApi\Test\Api\StockRepository;
  8. use Magento\Framework\Webapi\Rest\Request;
  9. use Magento\InventoryApi\Api\Data\StockInterface;
  10. use Magento\TestFramework\Assert\AssertArrayContains;
  11. use Magento\TestFramework\TestCase\WebapiAbstract;
  12. class UpdateTest extends WebapiAbstract
  13. {
  14. /**#@+
  15. * Service constants
  16. */
  17. const RESOURCE_PATH = '/V1/inventory/stocks';
  18. const SERVICE_NAME = 'inventoryApiStockRepositoryV1';
  19. /**#@-*/
  20. /**
  21. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock.php
  22. */
  23. public function testUpdate()
  24. {
  25. $stockId = 10;
  26. $expectedData = [
  27. StockInterface::NAME => 'stock-name-1-updated',
  28. ];
  29. $serviceInfo = [
  30. 'rest' => [
  31. 'resourcePath' => self::RESOURCE_PATH . '/' . $stockId,
  32. 'httpMethod' => Request::HTTP_METHOD_PUT,
  33. ],
  34. 'soap' => [
  35. 'service' => self::SERVICE_NAME,
  36. 'operation' => self::SERVICE_NAME . 'Save',
  37. ],
  38. ];
  39. if (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) {
  40. $this->_webApiCall($serviceInfo, ['stock' => $expectedData]);
  41. } else {
  42. $requestData = $expectedData;
  43. $requestData['stockId'] = $stockId;
  44. $this->_webApiCall($serviceInfo, ['stock' => $requestData]);
  45. }
  46. AssertArrayContains::assert($expectedData, $this->getStockDataById($stockId));
  47. }
  48. /**
  49. * @param int $stockId
  50. * @return array
  51. */
  52. private function getStockDataById(int $stockId): array
  53. {
  54. $serviceInfo = [
  55. 'rest' => [
  56. 'resourcePath' => self::RESOURCE_PATH . '/' . $stockId,
  57. 'httpMethod' => Request::HTTP_METHOD_GET,
  58. ],
  59. 'soap' => [
  60. 'service' => self::SERVICE_NAME,
  61. 'operation' => self::SERVICE_NAME . 'Get',
  62. ],
  63. ];
  64. $response = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
  65. ? $this->_webApiCall($serviceInfo)
  66. : $this->_webApiCall($serviceInfo, ['stockId' => $stockId]);
  67. self::assertArrayHasKey(StockInterface::STOCK_ID, $response);
  68. return $response;
  69. }
  70. }