1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?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(),
]);
}
}