9
9
10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
11
use Magento \CatalogInventory \Model \Stock \StockItemRepository ;
12
- use Magento \CatalogInventory \Ui \DataProvider \Product \AddIsInStockFieldToCollection ;
12
+ use Magento \CatalogInventory \Ui \DataProvider \Product \AddQuantityAndStockStatusFieldToCollection ;
13
13
use PHPUnit \Framework \TestCase ;
14
14
use Magento \TestFramework \Helper \Bootstrap ;
15
+ use Magento \CatalogInventory \Api \StockItemCriteriaInterface ;
16
+ use Magento \CatalogInventory \Api \StockRegistryInterface ;
15
17
16
18
/**
17
19
* Quantity and stock status test
@@ -44,19 +46,16 @@ protected function setUp()
44
46
*/
45
47
public function testProductStockStatus ()
46
48
{
47
- /** @var ProductRepositoryInterface $productRepository */
48
- $ productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
49
- $ product = $ productRepository ->get ('simple ' );
50
- $ productId = $ product ->getId ();
51
-
52
49
/** @var StockItemRepository $stockItemRepository */
53
50
$ stockItemRepository = $ this ->objectManager ->create (StockItemRepository::class);
54
51
55
- $ stockItem = $ stockItemRepository ->get ($ productId );
52
+ /** @var StockRegistryInterface $stockRegistry */
53
+ $ stockRegistry = $ this ->objectManager ->create (StockRegistryInterface::class);
54
+
55
+ $ stockItem = $ stockRegistry ->getStockItemBySku ('simple ' );
56
56
$ stockItem ->setIsInStock (false );
57
57
$ stockItemRepository ->save ($ stockItem );
58
- $ savedStockItem = $ stockItemRepository ->get ($ productId );
59
- $ savedStockStatus = $ savedStockItem ->getData ('is_in_stock ' );
58
+ $ savedStockStatus = (int )$ stockItem ->getIsInStock ();
60
59
61
60
$ dataProvider = $ this ->objectManager ->create (
62
61
ProductDataProvider::class,
@@ -66,7 +65,7 @@ public function testProductStockStatus()
66
65
'requestFieldName ' => 'id ' ,
67
66
'addFieldStrategies ' => [
68
67
'quantity_and_stock_status ' =>
69
- $ this ->objectManager ->get (AddIsInStockFieldToCollection ::class)
68
+ $ this ->objectManager ->get (AddQuantityAndStockStatusFieldToCollection ::class)
70
69
]
71
70
]
72
71
);
0 commit comments