/** * TODO: Cover with unit tests the other methods in the repository * test GetList */ public function testGetList() { $fieldName = 'field'; $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $collectionMock = $this->getMock('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection', [], [], '', false); $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false); $filterGroupFilterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false); $sortOrderMock = $this->getMock('\\Magento\\Framework\\Api\\SortOrder', [], [], '', false); $itemsMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false); $extensionAttributes = $this->getMock('\\Magento\\Sales\\Api\\Data\\OrderExtension', ['getShippingAssignments'], [], '', false); $shippingAssignmentBuilder = $this->getMock('\\Magento\\Sales\\Model\\Order\\ShippingAssignmentBuilder', [], [], '', false); $itemsMock->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes); $extensionAttributes->expects($this->any())->method('getShippingAssignments')->willReturn($shippingAssignmentBuilder); $this->searchResultFactory->expects($this->once())->method('create')->willReturn($collectionMock); $searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]); $filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterGroupFilterMock]); $filterGroupFilterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('eq'); $filterGroupFilterMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName); $filterGroupFilterMock->expects($this->once())->method('getValue')->willReturn('value'); $sortOrderMock->expects($this->once())->method('getDirection'); $searchCriteriaMock->expects($this->once())->method('getSortOrders')->willReturn([$sortOrderMock]); $sortOrderMock->expects($this->atLeastOnce())->method('getField')->willReturn($fieldName); $collectionMock->expects($this->once())->method('addFieldToFilter')->willReturn(SortOrder::SORT_ASC); $collectionMock->expects($this->once())->method('addOrder')->with($fieldName, 'DESC'); $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->willReturn(4); $collectionMock->expects($this->once())->method('setCurPage')->with(4); $searchCriteriaMock->expects($this->once())->method('getPageSize')->willReturn(42); $collectionMock->expects($this->once())->method('setPageSize')->with(42); $collectionMock->expects($this->once())->method('getItems')->willReturn([$itemsMock]); $this->assertEquals($collectionMock, $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); } }