123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- declare(strict_types=1);
- namespace Magento\InventorySales\Test\Integration\StockManagement;
- use Magento\Catalog\Api\ProductRepositoryInterface;
- use Magento\CatalogInventory\Model\StockManagement;
- use Magento\InventoryApi\Api\StockRepositoryInterface;
- use Magento\InventoryReservationsApi\Model\CleanupReservationsInterface;
- use Magento\InventoryReservationsApi\Model\AppendReservationsInterface;
- use Magento\InventoryReservationsApi\Model\ReservationBuilderInterface;
- use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface;
- use Magento\Store\Api\WebsiteRepositoryInterface;
- use Magento\TestFramework\Helper\Bootstrap;
- use PHPUnit\Framework\TestCase;
- class ReservationPlacingDuringBackItemQtyTest extends TestCase
- {
- /**
- * @var GetProductSalableQtyInterface
- */
- private $getProductSalableQty;
- /**
- * @var ProductRepositoryInterface
- */
- private $productRepository;
- /**
- * @var StockRepositoryInterface
- */
- private $stockRepository;
- /**
- * @var WebsiteRepositoryInterface
- */
- private $websiteRepository;
- /**
- * @var ReservationBuilderInterface
- */
- private $reservationBuilder;
- /**
- * @var AppendReservationsInterface
- */
- private $appendReservations;
- /**
- * @var CleanupReservationsInterface
- */
- private $cleanupReservations;
- /**
- * @var StockManagement
- */
- private $stockManagement;
- protected function setUp()
- {
- $this->getProductSalableQty = Bootstrap::getObjectManager()->get(GetProductSalableQtyInterface::class);
- $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
- $this->stockRepository = Bootstrap::getObjectManager()->get(StockRepositoryInterface::class);
- $this->websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepositoryInterface::class);
- $this->reservationBuilder = Bootstrap::getObjectManager()->get(ReservationBuilderInterface::class);
- $this->appendReservations = Bootstrap::getObjectManager()->get(AppendReservationsInterface::class);
- $this->cleanupReservations = Bootstrap::getObjectManager()->get(CleanupReservationsInterface::class);
- $this->stockManagement = Bootstrap::getObjectManager()->get(StockManagement::class);
- }
- /**
- * We broke transaction during indexation so we need to clean db state manually
- */
- protected function tearDown()
- {
- $this->cleanupReservations->execute();
- }
- /**
- * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
- * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
- * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
- * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
- * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
- * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
- * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php
- * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php
- *
- * @magentoDbIsolation disabled
- */
- public function testRevertProductsSale()
- {
- self::assertEquals(8.5, $this->getProductSalableQty->execute('SKU-1', 10));
- $product = $this->productRepository->get('SKU-1');
- $website = $this->websiteRepository->get('eu_website');
- $this->stockManagement->backItemQty($product->getId(), 3.5, $website->getId());
- self::assertEquals(12, $this->getProductSalableQty->execute('SKU-1', 10));
- $this->appendReservations->execute([
- // reserved 3.5 units for cleanup
- $this->reservationBuilder->setStockId(10)->setSku('SKU-1')->setQuantity(-3.5)->build(),
- ]);
- }
- }
|