GetStockItemDataTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 GetStockItemDataTest 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. *
  33. * @param string $sku
  34. * @param int $stockId
  35. * @param array|null $expectedData
  36. *
  37. * @dataProvider getStockItemDataDataProvider
  38. *
  39. * @magentoDbIsolation disabled
  40. */
  41. public function testGetStockItemData(string $sku, int $stockId, $expectedData)
  42. {
  43. $stockItemData = $this->getStockItemData->execute($sku, $stockId);
  44. self::assertEquals($expectedData, $stockItemData);
  45. }
  46. public function testGetStockItemDataReturnNullWhenTableDoesNotExist()
  47. {
  48. $stockItemData = $this->getStockItemData->execute('SKU-1', 10);
  49. self::assertNull($stockItemData);
  50. }
  51. /**
  52. * @return array
  53. */
  54. public function getStockItemDataDataProvider(): array
  55. {
  56. return [
  57. ['SKU-1', 10, [GetStockItemDataInterface::QUANTITY => 8.5, GetStockItemDataInterface::IS_SALABLE => 1]],
  58. ['SKU-1', 20, null],
  59. ['SKU-1', 30, [GetStockItemDataInterface::QUANTITY => 8.5, GetStockItemDataInterface::IS_SALABLE => 1]],
  60. ['SKU-2', 10, null],
  61. ['SKU-2', 20, [GetStockItemDataInterface::QUANTITY => 5, GetStockItemDataInterface::IS_SALABLE => 1]],
  62. ['SKU-2', 30, [GetStockItemDataInterface::QUANTITY => 5, GetStockItemDataInterface::IS_SALABLE => 1]],
  63. ['SKU-3', 10, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 0]],
  64. ['SKU-3', 20, null],
  65. ['SKU-3', 30, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 0]],
  66. ];
  67. }
  68. }