Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceItemsDeleteTest.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/source-items';
22  const RESOURCE_DELETE_PATH = '/V1/inventory/source-items-delete';
23  const SERVICE_NAME = 'inventoryApiSourceItemsDeleteV1';
31  public function testExecute()
32  {
33  $sourceItemsForDelete = [
34  [
36  SourceItemInterface::SKU => 'SKU-1',
37  ],
38  [
40  SourceItemInterface::SKU => 'SKU-1',
41  ],
42  ];
43  $expectedSourceItemsAfterDeleting = [
44  [
46  SourceItemInterface::SKU => 'SKU-1',
49  ],
50  [
51  SourceItemInterface::SOURCE_CODE => 'eu-disabled',
52  SourceItemInterface::SKU => 'SKU-1',
55  ],
56  ];
57 
58  $serviceInfo = [
59  'rest' => [
60  'resourcePath' => self::RESOURCE_DELETE_PATH . '?'
61  . http_build_query(['sourceItems' => $sourceItemsForDelete]),
62  'httpMethod' => Request::HTTP_METHOD_POST,
63  ],
64  'soap' => [
65  'service' => self::SERVICE_NAME,
66  'operation' => self::SERVICE_NAME . 'Execute',
67  ],
68  ];
69  (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
70  ? $this->_webApiCall($serviceInfo)
71  : $this->_webApiCall($serviceInfo, ['sourceItems' => $sourceItemsForDelete]);
72 
73  $actualData = $this->getSourceItems();
74 
75  self::assertEquals(2, $actualData['total_count']);
76  AssertArrayContains::assert($expectedSourceItemsAfterDeleting, $actualData['items']);
77  }
78 
82  private function getSourceItems(): array
83  {
84  $requestData = [
85  'searchCriteria' => [
87  [
88  'filters' => [
89  [
90  'field' => SourceItemInterface::SKU,
91  'value' => 'SKU-1',
92  'condition_type' => 'eq',
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' => 'inventoryApiSourceItemRepositoryV1',
106  'operation' => 'inventoryApiSourceItemRepositoryV1GetList',
107  ],
108  ];
109  return (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
110  ? $this->_webApiCall($serviceInfo)
111  : $this->_webApiCall($serviceInfo, $requestData);
112  }
113 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
static assert(array $expected, array $actual)