objectManager = Bootstrap::getObjectManager(); $this->cartManagement = $this->objectManager->get(CartManagementInterface::class); $this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class); $this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); $this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class); } /** * Test order placement with disabled inventory check, different quantity and out of stock status. * * @param int $qty * @param int $stockStatus * @return void * @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php * @magentoConfigFixture cataloginventory/options/enable_inventory_check 0 * @dataProvider getQtyAndStockStatusProvider */ public function testPlaceOrderWithDisabledInventoryCheck(int $qty, int $stockStatus): void { $quote = $this->getQuoteByReservedOrderId->execute('test_order_1'); $quote->getPayment()->setPoNumber(self::PURCHASE_ORDER_NUMBER); $quote->collectTotals()->save(); /** @var ProductInterface $product */ $product = $this->productRepository->get($quote->getItems()[0]->getSku(), false, null, true); $this->productRepository->save($product); $stockItem = $product->getExtensionAttributes()->getStockItem(); $stockItem->setQty($qty); $stockItem->setIsInStock($stockStatus); /** @var StockItemRepositoryInterface $stockItemRepository */ $stockItemRepository = $this->objectManager->get(StockItemRepositoryInterface::class); $stockItemRepository->save($stockItem); $this->expectException(LocalizedException::class); $this->cartManagement->placeOrder($quote->getId()); } /** * @return array */ public function getQtyAndStockStatusProvider(): array { return [ [0, 0], [100, 0], ]; } /** * Test order placement with disabled inventory check, positive quantity and in stock status. * * @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php * @magentoConfigFixture cataloginventory/options/enable_inventory_check 0 * @return void */ public function testSaveWithPositiveQuantityAndInStockWithInventoryCheckDisabled(): void { $quote = $this->getQuoteByReservedOrderId->execute('test_order_1'); $quote->getPayment()->setPoNumber(self::PURCHASE_ORDER_NUMBER); $quote->collectTotals()->save(); /** @var ProductInterface $product */ $product = $this->productRepository->get($quote->getItems()[0]->getSku(), false, null, true); $this->productRepository->save($product); $stockItem = $product->getExtensionAttributes()->getStockItem(); $stockItem->setQty(100); $stockItem->setIsInStock(1); /** @var StockItemRepositoryInterface $stockItemRepository */ $stockItemRepository = $this->objectManager->get(StockItemRepositoryInterface::class); $stockItemRepository->save($stockItem); $orderId = $this->cartManagement->placeOrder($quote->getId());; $order = $this->orderRepository->get($orderId); $orderItems = $order->getItems(); $this->assertCount(1, $orderItems); } }