Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReservationPlacingDuringBackItemQtyTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
19 use PHPUnit\Framework\TestCase;
20 
22 {
26  private $getProductSalableQty;
27 
31  private $productRepository;
32 
36  private $stockRepository;
37 
41  private $websiteRepository;
42 
46  private $reservationBuilder;
47 
51  private $appendReservations;
52 
56  private $cleanupReservations;
57 
61  private $stockManagement;
62 
63  protected function setUp()
64  {
65  $this->getProductSalableQty = Bootstrap::getObjectManager()->get(GetProductSalableQtyInterface::class);
66  $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
67  $this->stockRepository = Bootstrap::getObjectManager()->get(StockRepositoryInterface::class);
68  $this->websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepositoryInterface::class);
69  $this->reservationBuilder = Bootstrap::getObjectManager()->get(ReservationBuilderInterface::class);
70  $this->appendReservations = Bootstrap::getObjectManager()->get(AppendReservationsInterface::class);
71  $this->cleanupReservations = Bootstrap::getObjectManager()->get(CleanupReservationsInterface::class);
72  $this->stockManagement = Bootstrap::getObjectManager()->get(StockManagement::class);
73  }
74 
78  protected function tearDown()
79  {
80  $this->cleanupReservations->execute();
81  }
82 
95  public function testRevertProductsSale()
96  {
97  self::assertEquals(8.5, $this->getProductSalableQty->execute('SKU-1', 10));
98 
99  $product = $this->productRepository->get('SKU-1');
100  $website = $this->websiteRepository->get('eu_website');
101  $this->stockManagement->backItemQty($product->getId(), 3.5, $website->getId());
102 
103  self::assertEquals(12, $this->getProductSalableQty->execute('SKU-1', 10));
104 
105  $this->appendReservations->execute([
106  // reserved 3.5 units for cleanup
107  $this->reservationBuilder->setStockId(10)->setSku('SKU-1')->setQuantity(-3.5)->build(),
108  ]);
109  }
110 }