/** * @inheritdoc */ public function getList(\Magento\CatalogInventory\Api\StockItemCriteriaInterface $criteria) { $queryBuilder = $this->queryBuilderFactory->create(); $queryBuilder->setCriteria($criteria); $queryBuilder->setResource($this->resource); $query = $queryBuilder->create(); $collection = $this->stockItemCollectionFactory->create(['query' => $query]); return $collection; }
public function testGetList() { $criteriaMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\StockItemCriteriaInterface')->getMock(); $queryBuilderMock = $this->getMockBuilder('Magento\\Framework\\DB\\QueryBuilder')->disableOriginalConstructor()->setMethods(['setCriteria', 'setResource', 'create'])->getMock(); $queryMock = $this->getMockBuilder('Magento\\Framework\\DB\\QueryInterface')->getMock(); $queryCollectionMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemCollectionInterface')->getMock(); $this->queryBuilderFactoryMock->expects($this->once())->method('create')->willReturn($queryBuilderMock); $queryBuilderMock->expects($this->once())->method('setCriteria')->with($criteriaMock)->willReturnSelf(); $queryBuilderMock->expects($this->once())->method('setResource')->with($this->stockItemResourceMock)->willReturnSelf(); $queryBuilderMock->expects($this->once())->method('create')->willReturn($queryMock); $this->stockItemCollectionMock->expects($this->once())->method('create')->willReturn($queryCollectionMock); $this->assertEquals($queryCollectionMock, $this->model->getList($criteriaMock)); }