Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
UpdateDefaultSourceItemAtLegacyStockItemSaveTest Class Reference
Inheritance diagram for UpdateDefaultSourceItemAtLegacyStockItemSaveTest:

Public Member Functions

 testSaveLegacyStockItemAssignedToDefaultSource ()
 
 testSaveLegacyStockItemNotAssignedToDefaultSource ()
 
 testSaveLegacyStockItemWithoutDefaultSourceAssignment ()
 

Protected Member Functions

 setUp ()
 

Detailed Description

Definition at line 15 of file UpdateDefaultSourceItemAtLegacyStockItemSaveTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 27 of file UpdateDefaultSourceItemAtLegacyStockItemSaveTest.php.

28  {
29  parent::setUp();
30 
31  $this->stockRegistry = Bootstrap::getObjectManager()->create(StockRegistryInterface::class);
32  $this->getDefaultSourceItemBySku = Bootstrap::getObjectManager()->get(GetDefaultSourceItemBySku::class);
33  }

◆ testSaveLegacyStockItemAssignedToDefaultSource()

testSaveLegacyStockItemAssignedToDefaultSource ( )

@magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php @magentoDataFixture ../../../../app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php @magentoDbIsolation enabled

Exceptions

Definition at line 43 of file UpdateDefaultSourceItemAtLegacyStockItemSaveTest.php.

44  {
45  $stockItem = $this->stockRegistry->getStockItemBySku('SKU-1');
46  $stockItem->setQty(10);
47  $this->stockRegistry->updateStockItemBySku('SKU-1', $stockItem);
48 
49  $defaultSourceItem = $this->getDefaultSourceItemBySku->execute('SKU-1');
50  self::assertEquals(
51  10,
52  $defaultSourceItem->getQuantity(),
53  'Quantity is not updated in default source when legacy stock is updated and product was'
54  . 'previously assigned to default source'
55  );
56  }

◆ testSaveLegacyStockItemNotAssignedToDefaultSource()

testSaveLegacyStockItemNotAssignedToDefaultSource ( )

@magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php @magentoDataFixture ../../../../app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php @magentoDbIsolation enabled

Exceptions

Definition at line 66 of file UpdateDefaultSourceItemAtLegacyStockItemSaveTest.php.

67  {
68  $stockItem = $this->stockRegistry->getStockItemBySku('SKU-2');
69  $stockItem->setQty(10);
70  $this->stockRegistry->updateStockItemBySku('SKU-2', $stockItem);
71 
72  $defaultSourceItem = $this->getDefaultSourceItemBySku->execute('SKU-2');
73  self::assertEquals(
74  10,
75  $defaultSourceItem->getQuantity(),
76  'Quantity is not updated in default source when legacy stock is updated'
77  );
78 
79  // SKU-3 is out of stock and not assigned to default source
80  $stockItem = $this->stockRegistry->getStockItemBySku('SKU-3');
81  $stockItem->setQty(10);
82  $this->stockRegistry->updateStockItemBySku('SKU-3', $stockItem);
83 
84  $defaultSourceItem = $this->getDefaultSourceItemBySku->execute('SKU-3');
85  self::assertEquals(
86  10,
87  $defaultSourceItem->getQuantity(),
88  'Quantity is not updated in default source when legacy stock is updated and product was not '
89  . 'previously assigned to default source'
90  );
91  }

◆ testSaveLegacyStockItemWithoutDefaultSourceAssignment()

testSaveLegacyStockItemWithoutDefaultSourceAssignment ( )

@magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php @magentoDbIsolation enabled

Exceptions

Definition at line 100 of file UpdateDefaultSourceItemAtLegacyStockItemSaveTest.php.

101  {
102  // SKU-3 is out of stock and not assigned to default source
103  $stockItem = $this->stockRegistry->getStockItemBySku('SKU-3');
104  $stockItem->setQty(0);
105  $stockItem->setIsInStock(false);
106  $this->stockRegistry->updateStockItemBySku('SKU-3', $stockItem);
107 
108  $defaultSourceItem = $this->getDefaultSourceItemBySku->execute('SKU-3');
109  self::assertNull(
110  $defaultSourceItem,
111  'Product is assigned to default source on legacy stock item save even if it should not be'
112  );
113 
114  // SKU-5 is out of stock and not assigned to default source
115  $stockItem = $this->stockRegistry->getStockItemBySku('SKU-5');
116  $stockItem->setQty(1);
117  $stockItem->setIsInStock(true);
118  $this->stockRegistry->updateStockItemBySku('SKU-5', $stockItem);
119 
120  $defaultSourceItem = $this->getDefaultSourceItemBySku->execute('SKU-5');
121  self::assertNotNull(
122  $defaultSourceItem,
123  'Product is not assigned to default source on legacy stock item save even if it should be'
124  );
125  }

The documentation for this class was generated from the following file: