/**
  * @covers \Magento\CatalogInventory\Service\V1\StockStatusService::getLowStockItems
  */
 public function testGetterOfLowStockItems()
 {
     $websiteId = 1;
     $criteriaData = ['qty' => 1, 'current_page' => 1, 'page_size' => 10];
     $scope = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $scope->expects($this->any())->method('getId')->will($this->returnValue($websiteId));
     $this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValue($scope));
     $builder = $this->getMockBuilder('Magento\\Framework\\Service\\Data\\AbstractObjectBuilder')->disableOriginalConstructor()->getMock();
     $builder->expects($this->any())->method('getData')->will($this->returnValue($criteriaData));
     $statusItem = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Stock\\Status')->setMethods(['__wakeup', 'getSku'])->disableOriginalConstructor()->getMock();
     $statusItem->expects($this->any())->method('getSku')->will($this->returnValue('test_sku'));
     $collection = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Resource\\Stock\\Status\\Collection')->disableOriginalConstructor()->getMock();
     $collection->expects($this->any())->method('getSize')->will($this->returnValue(1));
     $collection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$statusItem])));
     $this->itemsFactory->expects($this->once())->method('create')->will($this->returnValue($collection));
     /** @var \Magento\Framework\Service\Data\AbstractObjectBuilder $builder */
     $lowStockCriteria = new Data\LowStockCriteria($builder);
     // Expected results
     $collection->expects($this->atLeastOnce())->method('addWebsiteFilter')->with($scope);
     $collection->expects($this->atLeastOnce())->method('addQtyFilter')->with($criteriaData['qty']);
     $collection->expects($this->atLeastOnce())->method('setCurPage')->with($criteriaData['current_page']);
     $collection->expects($this->atLeastOnce())->method('setPageSize')->with($criteriaData['page_size']);
     $this->lowStockResultBuilder->expects($this->atLeastOnce())->method('setSearchCriteria')->with($lowStockCriteria);
     $this->lowStockResultBuilder->expects($this->atLeastOnce())->method('setTotalCount')->with(1);
     $this->lowStockResultBuilder->expects($this->atLeastOnce())->method('setItems')->with(['test_sku']);
     // Run tested method
     $this->model->getLowStockItems($lowStockCriteria);
 }
示例#2
0
 /**
  * Retrieves a list of SKU's with low inventory qty
  *
  * {@inheritdoc}
  */
 public function getLowStockItems($lowStockCriteria)
 {
     /** @var \Magento\CatalogInventory\Model\Resource\Stock\Status\Collection $itemCollection */
     $itemCollection = $this->itemsFactory->create();
     $itemCollection->addWebsiteFilter($this->scopeResolver->getScope());
     $itemCollection->addQtyFilter($lowStockCriteria->getQty());
     $itemCollection->setCurPage($lowStockCriteria->getCurrentPage());
     $itemCollection->setPageSize($lowStockCriteria->getPageSize());
     $countOfItems = $itemCollection->getSize();
     $listOfSku = [];
     foreach ($itemCollection as $item) {
         $listOfSku[] = $item->getSku();
     }
     $this->lowStockResultBuilder->setSearchCriteria($lowStockCriteria);
     $this->lowStockResultBuilder->setTotalCount($countOfItems);
     $this->lowStockResultBuilder->setItems($listOfSku);
     return $this->lowStockResultBuilder->create();
 }
示例#3
0
 /**
  * @expectedException \Magento\Framework\Exception\State\InitException
  */
 public function testGetScopeWithInvalidScope()
 {
     $scopeMock = new \StdClass();
     $this->_storeManagerMock->expects($this->once())->method('getWebsite')->with(0)->will($this->returnValue($scopeMock));
     $this->assertEquals($scopeMock, $this->_model->getScope());
 }