Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultStockTest.php
Go to the documentation of this file.
1 <?php
8 
13 class DefaultStockTest extends \PHPUnit\Framework\TestCase
14 {
18  private $indexer;
19 
23  private $stockConfiguration;
24 
25  protected function setUp()
26  {
28  \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock::class
29  );
30  $this->stockConfiguration = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
31  \Magento\CatalogInventory\Api\StockConfigurationInterface::class
32  );
33  }
34 
43  public function testReindexEntity()
44  {
46  $productRepository = $this->getObject(\Magento\Catalog\Model\ProductRepository::class);
48  $websiteRepository = $this->getObject(
49  \Magento\Store\Api\WebsiteRepositoryInterface::class
50  );
51  $product = $productRepository->get('simple');
52  $testWebsite = $websiteRepository->get('test');
53  $product->setWebsiteIds([1, $testWebsite->getId()])->save();
54 
56  $criteriaFactory = $this->getObject(
57  \Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory::class
58  );
60  $stockStatusRepository = $this->getObject(
61  \Magento\CatalogInventory\Api\StockStatusRepositoryInterface::class
62  );
63  $criteria = $criteriaFactory->create();
64  $criteria->setProductsFilter([$product->getId()]);
65  $criteria->addFilter('website', 'website_id', $this->stockConfiguration->getDefaultScopeId());
66  $items = $stockStatusRepository->getList($criteria)->getItems();
67  $this->assertEquals($product->getId(), $items[$product->getId()]->getProductId());
68  }
69 
70  private function getObject($class)
71  {
72  return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
73  $class
74  );
75  }
76 }
$stockStatusRepository
$_option $_optionId $class
Definition: date.phtml:13
$items