ReservationPlacingOnCanSubtractQtySetToZeroTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\StockManagement;
  8. use Magento\InventoryReservationsApi\Model\CleanupReservationsInterface;
  9. use Magento\InventoryReservationsApi\Model\GetReservationsQuantityInterface;
  10. use Magento\InventoryReservationsApi\Model\AppendReservationsInterface;
  11. use Magento\InventoryReservationsApi\Model\ReservationBuilderInterface;
  12. use Magento\TestFramework\Helper\Bootstrap;
  13. use PHPUnit\Framework\TestCase;
  14. class ReservationPlacingOnCanSubtractQtySetToZeroTest extends TestCase
  15. {
  16. /**
  17. * @var AppendReservationsInterface
  18. */
  19. private $appendReservations;
  20. /**
  21. * @var ReservationBuilderInterface
  22. */
  23. private $reservationBuilder;
  24. /**
  25. * @var GetReservationsQuantityInterface
  26. */
  27. private $getReservationQuantity;
  28. protected function setUp()
  29. {
  30. $this->appendReservations = Bootstrap::getObjectManager()->get(AppendReservationsInterface::class);
  31. $this->reservationBuilder = Bootstrap::getObjectManager()->get(ReservationBuilderInterface::class);
  32. $this->getReservationQuantity = Bootstrap::getObjectManager()->get(GetReservationsQuantityInterface::class);
  33. }
  34. /**
  35. * We broke transaction during indexation so we need to clean db state manually
  36. */
  37. protected function tearDown()
  38. {
  39. Bootstrap::getObjectManager()->get(CleanupReservationsInterface::class)->execute();
  40. }
  41. /**
  42. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  43. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  44. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  45. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  46. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  47. * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
  48. * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php
  49. * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php
  50. * @magentoConfigFixture default_store cataloginventory/options/can_subtract 0
  51. *
  52. * @magentoDbIsolation disabled
  53. */
  54. public function testPlacingReservationOnCanSubtractQtySetToZero()
  55. {
  56. $this->appendReservations->execute(
  57. [
  58. $this->reservationBuilder->setStockId(10)->setSku('SKU-1')->setQuantity(2)->build()
  59. ]
  60. );
  61. self::assertEquals(0, $this->getReservationQuantity->execute('SKU-1', 10));
  62. }
  63. }