21
21
use Magento \Quote \Api \Data \CartInterface ;
22
22
use Magento \Quote \Api \Data \CartItemInterface ;
23
23
use Magento \Quote \Api \Data \CartItemInterfaceFactory ;
24
+ use Magento \Sales \Api \OrderManagementInterface ;
24
25
use Magento \Sales \Api \OrderRepositoryInterface ;
25
26
use Magento \Store \Api \Data \StoreInterface ;
26
27
use Magento \Store \Api \StoreRepositoryInterface ;
28
+ use Magento \Store \Model \StoreManagerInterface ;
27
29
use PHPUnit \Framework \TestCase ;
28
30
use Magento \TestFramework \Helper \Bootstrap ;
29
31
use Magento \InventoryReservations \Model \CleanupReservationsInterface ;
30
- use Magento \InventoryReservations \Model \ReservationBuilderInterface ;
31
- use Magento \InventoryReservationsApi \Api \AppendReservationsInterface ;
32
32
use Magento \Catalog \Api \ProductRepositoryInterface ;
33
33
use Magento \InventoryApi \Api \StockRepositoryInterface ;
34
34
35
35
/**
36
36
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
37
37
*/
38
- class PlaceOrderOnNotDefaultSourceTest extends TestCase
38
+ class PlaceOrderOnNotDefaultStockTest extends TestCase
39
39
{
40
40
/**
41
41
* @var CleanupReservationsInterface
@@ -62,16 +62,6 @@ class PlaceOrderOnNotDefaultSourceTest extends TestCase
62
62
*/
63
63
private $ cartItemFactory ;
64
64
65
- /**
66
- * @var AppendReservationsInterface
67
- */
68
- private $ appendReservations ;
69
-
70
- /**
71
- * @var ReservationBuilderInterface
72
- */
73
- private $ reservationBuilder ;
74
-
75
65
/**
76
66
* @var StockRepositoryInterface
77
67
*/
@@ -97,20 +87,30 @@ class PlaceOrderOnNotDefaultSourceTest extends TestCase
97
87
*/
98
88
private $ registry ;
99
89
90
+ /**
91
+ * @var OrderManagementInterface
92
+ */
93
+ private $ orderManagement ;
94
+
95
+ /**
96
+ * @var StoreManagerInterface
97
+ */
98
+ private $ storeManager ;
99
+
100
100
protected function setUp ()
101
101
{
102
102
$ this ->registry = Bootstrap::getObjectManager ()->get (Registry::class);
103
103
$ this ->stockRepository = Bootstrap::getObjectManager ()->get (StockRepositoryInterface::class);
104
104
$ this ->storeRepository = Bootstrap::getObjectManager ()->get (StoreRepositoryInterface::class);
105
+ $ this ->storeManager = Bootstrap::getObjectManager ()->get (StoreManagerInterface::class);
105
106
$ this ->cartManagement = Bootstrap::getObjectManager ()->get (CartManagementInterface::class);
106
107
$ this ->cartRepository = Bootstrap::getObjectManager ()->get (CartRepositoryInterface::class);
107
108
$ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
108
109
$ this ->searchCriteriaBuilder = Bootstrap::getObjectManager ()->get (SearchCriteriaBuilder::class);
109
110
$ this ->cartItemFactory = Bootstrap::getObjectManager ()->get (CartItemInterfaceFactory::class);
110
111
$ this ->cleanupReservations = Bootstrap::getObjectManager ()->get (CleanupReservationsInterface::class);
111
- $ this ->appendReservations = Bootstrap::getObjectManager ()->get (AppendReservationsInterface::class);
112
- $ this ->reservationBuilder = Bootstrap::getObjectManager ()->get (ReservationBuilderInterface::class);
113
112
$ this ->orderRepository = Bootstrap::getObjectManager ()->get (OrderRepositoryInterface::class);
113
+ $ this ->orderManagement = Bootstrap::getObjectManager ()->get (OrderManagementInterface::class);
114
114
}
115
115
116
116
/**
@@ -130,13 +130,9 @@ protected function setUp()
130
130
*/
131
131
public function testPlaceOrderWithInStockProduct ()
132
132
{
133
- $ this ->markTestSkipped (
134
- 'Fix Integration Test for placing Order https://github.com/magento-engcom/msi/issues/687 '
135
- );
136
- $ sku = 'SKU-1 ' ;
137
- $ stockId = 10 ;
138
- $ quoteItemQty = 4 ;
139
- $ reservedDuringCheckoutQty = 1.5 ;
133
+ $ sku = 'SKU-2 ' ;
134
+ $ stockId = 30 ;
135
+ $ quoteItemQty = 2.2 ;
140
136
141
137
$ cart = $ this ->getCartByStockId ($ stockId );
142
138
$ product = $ this ->productRepository ->get ($ sku );
@@ -154,15 +150,10 @@ public function testPlaceOrderWithInStockProduct()
154
150
);
155
151
$ cart ->addItem ($ cartItem );
156
152
$ this ->cartRepository ->save ($ cart );
157
-
158
- $ this ->appendReservation ($ sku , -$ reservedDuringCheckoutQty , $ stockId );
159
-
160
153
$ orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
161
154
162
155
self ::assertNotNull ($ orderId );
163
156
164
- //cleanup
165
- $ this ->appendReservation ($ sku , $ reservedDuringCheckoutQty , $ stockId );
166
157
$ this ->deleteOrderById ((int )$ orderId );
167
158
}
168
159
@@ -183,13 +174,9 @@ public function testPlaceOrderWithInStockProduct()
183
174
*/
184
175
public function testPlaceOrderWithOutOffStockProduct ()
185
176
{
186
- $ this ->markTestSkipped (
187
- 'Fix Integration Test for placing Order https://github.com/magento-engcom/msi/issues/687 '
188
- );
189
- $ sku = 'SKU-1 ' ;
190
- $ stockId = 10 ;
191
- $ quoteItemQty = 4 ;
192
- $ reservedDuringCheckoutQty = 3.8 ;
177
+ $ sku = 'SKU-2 ' ;
178
+ $ stockId = 30 ;
179
+ $ quoteItemQty = 6.2 ;
193
180
194
181
$ cart = $ this ->getCartByStockId ($ stockId );
195
182
$ product = $ this ->productRepository ->get ($ sku );
@@ -208,32 +195,10 @@ public function testPlaceOrderWithOutOffStockProduct()
208
195
$ cart ->addItem ($ cartItem );
209
196
$ this ->cartRepository ->save ($ cart );
210
197
211
- //append reservation during checkout to make laking quantity in stock
212
- $ this ->appendReservation ($ sku , -$ reservedDuringCheckoutQty , $ stockId );
213
-
214
198
self ::expectException (LocalizedException::class);
215
199
$ orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
216
200
217
201
self ::assertNull ($ orderId );
218
-
219
- //cleanup
220
- $ this ->appendReservation ($ sku , $ reservedDuringCheckoutQty , $ stockId );
221
- }
222
-
223
- /**
224
- * @param string $productSku
225
- * @param float $qty
226
- * @param int $stockId
227
- * @return void
228
- * @throws CouldNotSaveException
229
- * @throws InputException
230
- * @throws ValidationException
231
- */
232
- private function appendReservation (string $ productSku , float $ qty , int $ stockId )
233
- {
234
- $ this ->appendReservations ->execute ([
235
- $ this ->reservationBuilder ->setStockId ($ stockId )->setSku ($ productSku )->setQuantity ($ qty )->build (),
236
- ]);
237
202
}
238
203
239
204
/**
@@ -261,6 +226,7 @@ private function getCartByStockId(int $stockId): CartInterface
261
226
}
262
227
/** @var StoreInterface $store */
263
228
$ store = $ this ->storeRepository ->get ($ storeCode );
229
+ $ this ->storeManager ->setCurrentStore ($ storeCode );
264
230
$ cart ->setStoreId ($ store ->getId ());
265
231
266
232
return $ cart ;
@@ -273,6 +239,7 @@ private function deleteOrderById(int $orderId)
273
239
{
274
240
$ this ->registry ->unregister ('isSecureArea ' );
275
241
$ this ->registry ->register ('isSecureArea ' , true );
242
+ $ this ->orderManagement ->cancel ($ orderId );
276
243
$ this ->orderRepository ->delete ($ this ->orderRepository ->get ($ orderId ));
277
244
$ this ->registry ->unregister ('isSecureArea ' );
278
245
$ this ->registry ->register ('isSecureArea ' , false );
0 commit comments