MinQtyConditionTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventorySales\Test\Integration\GetStockItemData;
  8. use Magento\InventorySalesApi\Model\GetStockItemDataInterface;
  9. use Magento\TestFramework\Helper\Bootstrap;
  10. use PHPUnit\Framework\TestCase;
  11. class MinQtyConditionTest extends TestCase
  12. {
  13. /**
  14. * @var GetStockItemDataInterface
  15. */
  16. private $getStockItemData;
  17. /**
  18. * @inheritdoc
  19. */
  20. protected function setUp()
  21. {
  22. parent::setUp();
  23. $this->getStockItemData = Bootstrap::getObjectManager()->get(GetStockItemDataInterface::class);
  24. }
  25. /**
  26. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  27. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  28. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  29. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  30. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  31. * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
  32. * @magentoConfigFixture default_store cataloginventory/item_options/min_qty 5
  33. *
  34. * @param string $sku
  35. * @param int $stockId
  36. * @param $expectedData
  37. * @return void
  38. *
  39. * @dataProvider executeWithMinQtyDataProvider
  40. *
  41. * @magentoDbIsolation disabled
  42. */
  43. public function testExecuteWithMinQty(string $sku, int $stockId, $expectedData)
  44. {
  45. $stockItemData = $this->getStockItemData->execute($sku, $stockId);
  46. self::assertEquals($expectedData, $stockItemData);
  47. }
  48. /**
  49. * @return array
  50. */
  51. public function executeWithMinQtyDataProvider(): array
  52. {
  53. return [
  54. ['SKU-1', 10, [GetStockItemDataInterface::QUANTITY => 8.5, GetStockItemDataInterface::IS_SALABLE => 1]],
  55. ['SKU-1', 20, null],
  56. ['SKU-1', 30, [GetStockItemDataInterface::QUANTITY => 8.5, GetStockItemDataInterface::IS_SALABLE => 1]],
  57. ['SKU-2', 10, null],
  58. ['SKU-2', 20, [GetStockItemDataInterface::QUANTITY => 5, GetStockItemDataInterface::IS_SALABLE => 0]],
  59. ['SKU-2', 30, [GetStockItemDataInterface::QUANTITY => 5, GetStockItemDataInterface::IS_SALABLE => 0]],
  60. ['SKU-3', 10, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 0]],
  61. ['SKU-3', 20, null],
  62. ['SKU-3', 30, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 0]],
  63. ];
  64. }
  65. /**
  66. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  67. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  68. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  69. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  70. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  71. * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
  72. * @magentoConfigFixture default_store cataloginventory/item_options/min_qty 5
  73. * @magentoConfigFixture default_store cataloginventory/item_options/manage_stock 0
  74. *
  75. * @param string $sku
  76. * @param int $stockId
  77. * @param $expectedData
  78. * @return void
  79. *
  80. * @dataProvider executeWithManageStockFalseAndMinQty
  81. *
  82. * @magentoDbIsolation disabled
  83. */
  84. public function testExecuteWithManageStockFalseAndMinQty(string $sku, int $stockId, $expectedData)
  85. {
  86. $stockItemData = $this->getStockItemData->execute($sku, $stockId);
  87. self::assertEquals($expectedData, $stockItemData);
  88. }
  89. /**
  90. * @return array
  91. */
  92. public function executeWithManageStockFalseAndMinQty(): array
  93. {
  94. return [
  95. ['SKU-1', 10, [GetStockItemDataInterface::QUANTITY => 8.5, GetStockItemDataInterface::IS_SALABLE => 1]],
  96. ['SKU-1', 20, null],
  97. ['SKU-1', 30, [GetStockItemDataInterface::QUANTITY => 8.5, GetStockItemDataInterface::IS_SALABLE => 1]],
  98. ['SKU-2', 10, null],
  99. ['SKU-2', 20, [GetStockItemDataInterface::QUANTITY => 5, GetStockItemDataInterface::IS_SALABLE => 1]],
  100. ['SKU-2', 30, [GetStockItemDataInterface::QUANTITY => 5, GetStockItemDataInterface::IS_SALABLE => 1]],
  101. ['SKU-3', 10, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 1]],
  102. ['SKU-3', 20, null],
  103. ['SKU-3', 30, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 1]],
  104. ];
  105. }
  106. }