6 declare(strict_types=1);
18 use PHPUnit\Framework\TestCase;
25 private $reservationBuilder;
30 private $appendReservations;
35 private $cleanupReservations;
40 private $isProductSalableForRequestedQty;
45 private $getStockItemConfiguration;
50 private $saveStockItemConfiguration;
62 $this->isProductSalableForRequestedQty
65 GetStockItemConfigurationInterface::class
68 SaveStockItemConfigurationInterface::class
92 $this->isProductSalableForRequestedQty->execute($sku, $stockId, $qty)->isSalable()
102 [
'SKU-1', 10, 1,
true],
103 [
'SKU-1', 20, 1,
false],
104 [
'SKU-1', 30, 1,
true],
105 [
'SKU-2', 10, 1,
false],
106 [
'SKU-2', 20, 1,
true],
107 [
'SKU-2', 30, 1,
true],
108 [
'SKU-3', 10, 1,
false],
109 [
'SKU-3', 20, 1,
false],
110 [
'SKU-3', 30, 1,
false],
132 public function testProductIsSalableWithUseConfigMinQty(
string $sku,
int $stockId,
float $qty,
bool $isSalable)
135 $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
136 $stockItemConfiguration->setUseConfigMinQty(
true);
137 $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
141 $this->isProductSalableForRequestedQty->execute($sku, $stockId, $qty)->isSalable()
151 [
'SKU-1', 10, 3,
true],
152 [
'SKU-1', 10, 4,
false],
153 [
'SKU-1', 30, 3,
true],
154 [
'SKU-1', 30, 4,
false],
155 [
'SKU-2', 20, 1,
false],
156 [
'SKU-2', 30, 1,
false],
157 [
'SKU-3', 10, 1,
false],
158 [
'SKU-3', 30, 1,
false],
178 public function testProductIsSalableWithMinQty(
string $sku,
int $stockId,
float $qty,
bool $isSalable)
181 $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
182 $stockItemConfiguration->setUseConfigMinQty(
false);
183 $stockItemConfiguration->setMinQty(5);
184 $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
188 $this->isProductSalableForRequestedQty->execute($sku, $stockId, $qty)->isSalable()
198 [
'SKU-1', 10, 3,
true],
199 [
'SKU-1', 10, 4,
false],
200 [
'SKU-1', 30, 3,
true],
201 [
'SKU-1', 30, 4,
false],
202 [
'SKU-2', 20, 1,
false],
203 [
'SKU-2', 30, 1,
false],
204 [
'SKU-3', 10, 1,
false],
205 [
'SKU-3', 30, 1,
false],
222 $this->appendReservations->execute([
223 $this->reservationBuilder->setStockId(10)->setSku(
'SKU-1')->setQuantity(-8.5)->build(),
225 self::assertFalse($this->isProductSalableForRequestedQty->execute(
'SKU-1', 10, 1)->isSalable());
227 $this->appendReservations->execute([
229 $this->reservationBuilder->setStockId(10)->setSku(
'SKU-1')->setQuantity(8.5)->build(),
231 $this->cleanupReservations->execute();
productIsSalableWithMinQtyDataProvider()
testProductIsSalable(string $sku, int $stockId, float $qty, bool $isSalable)
testProductIsOutOfStockIfReservationsArePresent()
productIsSalableDataProvider()
productIsSalableWithUseConfigMinQtyDataProvider()
static getObjectManager()