Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockSourceLinksSaveTest.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 SERVICE_NAME_SAVE = 'inventoryApiStockSourceLinksSaveV1';
23  const SERVICE_NAME_DELETE = 'inventoryApiStockSourceLinksDeleteV1';
24  const SERVICE_NAME_GET_LIST = 'inventoryApiGetStockSourceLinksV1';
31  public function testExecute()
32  {
33  $links = [
34  [
38  ],
39  [
43  ],
44  ];
45 
46  $serviceInfo = [
47  'rest' => [
48  'resourcePath' => self::RESOURCE_PATH,
49  'httpMethod' => Request::HTTP_METHOD_POST,
50  ],
51  'soap' => [
52  'service' => self::SERVICE_NAME_SAVE,
53  'operation' => self::SERVICE_NAME_SAVE . 'Execute',
54  ],
55  ];
56  $this->_webApiCall($serviceInfo, ['links' => $links]);
57 
58  $actualData = $this->getStockSourceLinks();
59 
60  self::assertEquals(2, $actualData['total_count']);
61  AssertArrayContains::assert($links, $actualData['items']);
62  }
63 
64  protected function tearDown()
65  {
66  $links = [
67  [
71  ],
72  [
76  ],
77  ];
78 
79  $serviceInfo = [
80  'rest' => [
81  'resourcePath' => self::RESOURCE_PATH . '?'
82  . http_build_query(['links' => $links]),
83  'httpMethod' => Request::HTTP_METHOD_POST,
84  ],
85  'soap' => [
86  'service' => self::SERVICE_NAME_DELETE,
87  'operation' => self::SERVICE_NAME_DELETE . 'Execute',
88  ],
89  ];
90 
91  (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST)
92  ? $this->_webApiCall($serviceInfo)
93  : $this->_webApiCall($serviceInfo, ['links' => $links]);
94 
95  parent::tearDown();
96  }
97 
101  private function getStockSourceLinks(): array
102  {
103  $requestData = [
104  'searchCriteria' => [
106  [
107  'filters' => [
108  [
110  'value' => 10,
111  'condition_type' => 'eq',
112  ],
113  ],
114  ],
115  ],
116  ],
117  ];
118 
119  $serviceInfo = [
120  'rest' => [
121  'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData),
122  'httpMethod' => Request::HTTP_METHOD_GET,
123  ],
124  'soap' => [
125  'service' => self::SERVICE_NAME_GET_LIST,
126  'operation' => self::SERVICE_NAME_GET_LIST . 'Execute',
127  ],
128  ];
129 
130  return (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
131  ? $this->_webApiCall($serviceInfo)
132  : $this->_webApiCall($serviceInfo, $requestData);
133  }
134 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
static assert(array $expected, array $actual)