Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ByStockItemRepositoryTest.php
Go to the documentation of this file.
1 <?php
7 
14 
15 class ByStockItemRepositoryTest extends \PHPUnit\Framework\TestCase
16 {
20  private $productRepository;
21 
25  private $stockItemRepository;
26 
30  private $dataObjectHelper;
31 
35  private $stockItemDataChecker;
36 
40  private $stockItemData = [
44  ];
45 
46  public function setUp()
47  {
49  $this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
50  $this->stockItemRepository = $objectManager->get(StockItemRepositoryInterface::class);
51  $this->dataObjectHelper = $objectManager->get(DataObjectHelper::class);
52  $this->stockItemDataChecker = $objectManager->get(StockItemDataChecker::class);
53  }
54 
61  public function testSave()
62  {
64  $product = $this->productRepository->get('simple', false, null, true);
65  $stockItem = $product->getExtensionAttributes()->getStockItem();
66  $this->dataObjectHelper->populateWithArray(
67  $stockItem,
68  $this->stockItemData,
69  StockItemInterface::class
70  );
71  $this->stockItemRepository->save($stockItem);
72 
73  $this->stockItemDataChecker->checkStockItemData('simple', $this->stockItemData);
74  }
75 }
$objectManager
Definition: bootstrap.php:17