Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockSourceLinksDeleteTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
17 {
21  const RESOURCE_PATH = '/V1/inventory/stock-source-links';
22  const RESOURCE_DELETE_PATH = '/V1/inventory/stock-source-links-delete';
23 
24  const SERVICE_NAME_SAVE = 'inventoryApiStockSourceLinksSaveV1';
25  const SERVICE_NAME_DELETE = 'inventoryApiStockSourceLinksDeleteV1';
26  const SERVICE_NAME_GET_LIST = 'inventoryApiGetStockSourceLinksV1';
34  public function testExecute()
35  {
36  $linksForDelete = [
37  [
40  ],
41  [
44  ],
45  ];
46  $expectedLinksAfterDeleting = [
47  [
50  ],
51  [
54  ],
55  ];
56 
57  $serviceInfo = [
58  'rest' => [
59  'resourcePath' => self::RESOURCE_DELETE_PATH . '?'
60  . http_build_query(['links' => $linksForDelete]),
61  'httpMethod' => Request::HTTP_METHOD_POST,
62  ],
63  'soap' => [
64  'service' => self::SERVICE_NAME_DELETE,
65  'operation' => self::SERVICE_NAME_DELETE . 'Execute',
66  ],
67  ];
68  (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
69  ? $this->_webApiCall($serviceInfo)
70  : $this->_webApiCall($serviceInfo, ['links' => $linksForDelete]);
71 
72  $actualData = $this->getStockSourceLinks();
73 
74  self::assertEquals(2, $actualData['total_count']);
75  AssertArrayContains::assert($expectedLinksAfterDeleting, $actualData['items']);
76  }
77 
81  private function getStockSourceLinks(): array
82  {
83  $requestData = [
84  'searchCriteria' => [
86  [
87  'filters' => [
88  [
90  'value' => 10,
91  'condition_type' => 'eq',
92  ],
93  ],
94  ],
95  ],
96  ],
97  ];
98 
99  $serviceInfo = [
100  'rest' => [
101  'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData),
102  'httpMethod' => Request::HTTP_METHOD_GET,
103  ],
104  'soap' => [
105  'service' => self::SERVICE_NAME_GET_LIST,
106  'operation' => self::SERVICE_NAME_GET_LIST . 'Execute',
107  ],
108  ];
109 
110  return (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
111  ? $this->_webApiCall($serviceInfo)
112  : $this->_webApiCall($serviceInfo, $requestData);
113  }
114 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
static assert(array $expected, array $actual)