GetDefaultSourceItemBySkuTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\InventoryCatalog\Test\Integration;
  8. use Magento\InventoryCatalog\Model\GetDefaultSourceItemBySku;
  9. use Magento\TestFramework\Helper\Bootstrap;
  10. use PHPUnit\Framework\TestCase;
  11. class GetDefaultSourceItemBySkuTest extends TestCase
  12. {
  13. /**
  14. * @var GetDefaultSourceItemBySku
  15. */
  16. private $getDefaultSourceItemBySku;
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $this->getDefaultSourceItemBySku = Bootstrap::getObjectManager()->get(GetDefaultSourceItemBySku::class);
  21. }
  22. /**
  23. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  24. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  25. * @magentoDataFixture ../../../../app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php
  26. */
  27. public function testExecuteOnDefaultSource()
  28. {
  29. self::assertNotNull(
  30. $this->getDefaultSourceItemBySku->execute('SKU-1'),
  31. 'Unable to find default source_item for a product assigned to Default source only'
  32. );
  33. self::assertNotNull(
  34. $this->getDefaultSourceItemBySku->execute('SKU-2'),
  35. 'Unable to find default source_item for a product assigned to Default source and others'
  36. );
  37. }
  38. /**
  39. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  40. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  41. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  42. */
  43. public function testExecuteOnNonDefaultSource()
  44. {
  45. self::assertNull(
  46. $this->getDefaultSourceItemBySku->execute('SKU-1'),
  47. 'Returned a wrong default source_item for a product assigned elsewhere'
  48. );
  49. }
  50. }