Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockRegistryTest.php
Go to the documentation of this file.
1 <?php
7 
11 class StockRegistryTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $model;
17 
21  protected $criteria;
22 
23  protected function setUp()
24  {
25  $this->criteria = $this->getMockBuilder(\Magento\CatalogInventory\Api\StockItemCriteriaInterface::class)
26  ->disableOriginalConstructor()
27  ->getMock();
28 
29  $criteriaFactory = $this->getMockBuilder(\Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory::class)
30  ->setMethods(['create'])
31  ->disableOriginalConstructor()
32  ->getMock();
33  $criteriaFactory->expects($this->once())->method('create')->willReturn($this->criteria);
34 
35  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->model = $objectManager->getObject(
37  \Magento\CatalogInventory\Model\StockRegistry::class,
38  [
39  'criteriaFactory' => $criteriaFactory
40  ]
41  );
42  }
43 
44  public function testGetLowStockItems()
45  {
46  $this->criteria->expects($this->once())->method('setLimit')->with(1, 0);
47  $this->criteria->expects($this->once())->method('setScopeFilter')->with(1);
48  $this->criteria->expects($this->once())->method('setQtyFilter')->with('<=');
49  $this->criteria->expects($this->once())->method('addField')->with('qty');
50  $this->model->getLowStockItems(1, 100);
51  }
52 }
$objectManager
Definition: bootstrap.php:17