orderCollectionFactory = $this->createPartialMock( \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class, ['create'] ); $this->orderConfig = $this->createMock(\Magento\Sales\Model\Order\Config::class); $this->block = $objectManager->getObject( \Magento\Paypal\Block\Billing\Agreement\View::class, [ 'orderCollectionFactory' => $this->orderCollectionFactory, 'orderConfig' => $this->orderConfig, ] ); } public function testGetRelatedOrders() { $visibleStatuses = []; $orderCollection = $this->createPartialMock( \Magento\Sales\Model\ResourceModel\Order\Collection::class, ['addFieldToSelect', 'addFieldToFilter', 'setOrder'] ); $orderCollection->expects($this->at(0)) ->method('addFieldToSelect') ->will($this->returnValue($orderCollection)); $orderCollection->expects($this->at(1)) ->method('addFieldToFilter') ->will($this->returnValue($orderCollection)); $orderCollection->expects($this->at(2)) ->method('addFieldToFilter') ->with('status', ['in' => $visibleStatuses]) ->will($this->returnValue($orderCollection)); $orderCollection->expects($this->at(3)) ->method('setOrder') ->will($this->returnValue($orderCollection)); $this->orderCollectionFactory->expects($this->once()) ->method('create') ->will($this->returnValue($orderCollection)); $this->orderConfig->expects($this->once()) ->method('getVisibleOnFrontStatuses') ->will($this->returnValue($visibleStatuses)); $this->block->getRelatedOrders(); } }