Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NegativeMinQtyTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 use PHPUnit\Framework\TestCase;
16 
17 class NegativeMinQtyTest extends TestCase
18 {
22  private $isProductSalableForRequestedQty;
23 
27  private $getStockItemConfiguration;
28 
32  private $saveStockItemConfiguration;
33 
37  protected function setUp()
38  {
39  parent::setUp();
40  $this->isProductSalableForRequestedQty = Bootstrap::getObjectManager()->get(
41  IsProductSalableForRequestedQtyInterface::class
42  );
43  $this->getStockItemConfiguration = Bootstrap::getObjectManager()->get(
44  GetStockItemConfigurationInterface::class
45  );
46  $this->saveStockItemConfiguration = Bootstrap::getObjectManager()->get(
47  SaveStockItemConfigurationInterface::class
48  );
49  }
50 
62  $sku,
63  $stockId,
64  $minQty,
65  $requestedQty,
66  $expectedSalability
67  ) {
68  $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
69  $stockItemConfiguration->setUseConfigBackorders(false);
70  $stockItemConfiguration->setBackorders(StockItemConfigurationInterface::BACKORDERS_YES_NONOTIFY);
71  $stockItemConfiguration->setUseConfigMinQty(false);
72  $stockItemConfiguration->setMinQty($minQty);
73  $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
74 
75  $this->assertEquals(
76  $expectedSalability,
77  $this->isProductSalableForRequestedQty->execute($sku, $stockId, $requestedQty)->isSalable()
78  );
79  }
80 
82  {
83  return [
84  'salable_qty' => ['SKU-1', 10, -4.5, 13, true],
85  'not_salable_qty' => ['SKU-1', 10, -4.5, 14, false],
86  ];
87  }
88 
102  $sku,
103  $stockId,
104  $requestedQty,
105  $expectedSalability
106  ) {
107  $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
108  $stockItemConfiguration->setUseConfigBackorders(true);
109  $stockItemConfiguration->setUseConfigMinQty(true);
110  $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
111 
112  $this->assertEquals(
113  $expectedSalability,
114  $this->isProductSalableForRequestedQty->execute($sku, $stockId, $requestedQty)->isSalable()
115  );
116  }
117 
119  {
120  return [
121  'salable_qty' => ['SKU-1', 10, 13, true],
122  'not_salable_qty' => ['SKU-1', 10, 14, false],
123  ];
124  }
125 }
testIsProductSalableForRequestedQtyWithBackordersEnabledGlobally( $sku, $stockId, $requestedQty, $expectedSalability)
testIsProductSalableForRequestedQtyWithBackordersEnabledAtProductLevel( $sku, $stockId, $minQty, $requestedQty, $expectedSalability)