/** * @param int $direction * @param string $expectedDirection * @dataProvider getListSuccessDataProvider */ public function testGetListSuccess($direction, $expectedDirection) { $searchResult = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartSearchResultsInterface', [], [], '', false); $searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $cartMock = $this->getMock('Magento\\Payment\\Model\\Cart', [], [], '', false); $filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false); $pageSize = 10; $this->searchResultsBuilderMock->expects($this->once())->method('setSearchCriteria'); $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false); $searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock])); //addFilterGroupToCollection() checks $filterGroupMock->expects($this->any())->method('getFilters')->will($this->returnValue([$filterMock])); $filterMock->expects($this->once())->method('getField')->will($this->returnValue('store_id')); $filterMock->expects($this->any())->method('getConditionType')->will($this->returnValue('eq')); $filterMock->expects($this->once())->method('getValue')->will($this->returnValue('filter_value')); //back in getList() $this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize); $this->searchResultsBuilderMock->expects($this->once())->method('setTotalCount')->with($pageSize); $sortOrderMock = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->setMethods(['getField', 'getDirection'])->disableOriginalConstructor()->getMock(); //foreach cycle $searchCriteriaMock->expects($this->once())->method('getSortOrders')->will($this->returnValue([$sortOrderMock])); $sortOrderMock->expects($this->once())->method('getField')->will($this->returnValue('id')); $sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction)); $this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection); $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1)); $searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10)); $this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1); $this->quoteCollectionMock->expects($this->once())->method('setPageSize')->with(10); $this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]); $this->searchResultsBuilderMock->expects($this->once())->method('setItems')->with([$cartMock]); $this->searchResultsBuilderMock->expects($this->once())->method('create')->will($this->returnValue($searchResult)); $this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock)); }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getList'); if (!$pluginInfo) { return parent::getList($searchCriteria); } else { return $this->___callPlugins('getList', func_get_args(), $pluginInfo); } }