Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceSelectionServiceTest.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-selection-algorithm-result';
22  const SERVICE_NAME = 'inventorySourceSelectionApiSourceSelectionServiceV1';
28  private $defaultAlgorithmCode;
29 
30  protected function setUp()
31  {
32  parent::setUp();
33  $this->defaultAlgorithmCode = Bootstrap::getObjectManager()->get(
34  GetDefaultSourceSelectionAlgorithmCodeInterface::class
35  );
36  }
37 
45  public function testSourceSelectionService()
46  {
47  $inventoryRequest = [
48  'stockId' => 10,
49  'items' => [
50  [
51  'sku' => 'SKU-1',
52  'qty' => 8
53  ],
54  [
55  'sku' => 'SKU-4',
56  'qty' => 4
57  ]
58  ]
59  ];
60 
61  $expectedResultData = [
62  'source_selection_items' => [
63  [
64  'source_code' => 'eu-1',
65  'sku' => 'SKU-1',
66  'qty_to_deduct' => 5.5,
67  'qty_available' => 5.5
68  ],
69  [
70  'source_code' => 'eu-2',
71  'sku' => 'SKU-1',
72  'qty_to_deduct' => 2.5,
73  'qty_available' => 3
74  ],
75  [
76  'source_code' => 'eu-2',
77  'sku' => 'SKU-4',
78  'qty_to_deduct' => 4,
79  'qty_available' => 6
80  ],
81  ],
82  'shippable' => 1
83  ];
84 
85  $algorithmCode = $this->defaultAlgorithmCode->execute();
86  $requestData = [
87  'inventoryRequest' => $inventoryRequest,
88  'algorithmCode' => $algorithmCode
89  ];
90 
91  $serviceInfo = [
92  'rest' => [
93  'resourcePath' => self::RESOURCE_PATH,
94  'httpMethod' => Request::HTTP_METHOD_POST,
95  ],
96  'soap' => [
97  'service' => self::SERVICE_NAME,
98  'operation' => self::SERVICE_NAME . 'Execute',
99  ],
100  ];
101 
102  $sourceSelectionAlgorithmResult = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST)
103  ? $this->_webApiCall($serviceInfo, $requestData)
104  : $this->_webApiCall($serviceInfo, $requestData);
105 
106  self::assertInternalType('array', $sourceSelectionAlgorithmResult);
107  self::assertNotEmpty($sourceSelectionAlgorithmResult);
108  AssertArrayContains::assert($expectedResultData, $sourceSelectionAlgorithmResult);
109  }
110 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
static assert(array $expected, array $actual)