contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class) ->disableOriginalConstructor() ->getMock(); $this->registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class) ->disableOriginalConstructor() ->getMock(); $paymentHelperMock = $this->getMockBuilder(\Magento\Payment\Helper\Data::class) ->disableOriginalConstructor() ->getMock(); $addressRendererMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Address\Renderer::class) ->disableOriginalConstructor() ->getMock(); $this->block = new \Magento\Sales\Block\Order\PrintShipment( $this->contextMock, $this->registryMock, $paymentHelperMock, $addressRendererMock ); $this->itemCollectionMock = $this->getMockBuilder(ItemCollection::class) ->disableOriginalConstructor() ->getMock(); } public function testIsPagerDisplayed() { $this->assertFalse($this->block->isPagerDisplayed()); } public function testGetItemsNoOrder() { $this->registryMock->expects($this->once()) ->method('registry') ->with('current_order') ->willReturn(null); $this->assertEmpty($this->block->getItems()); } public function testGetItemsSuccessful() { $orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class) ->disableOriginalConstructor() ->getMock(); $items = [5, 3, 1]; $this->registryMock->expects($this->exactly(2)) ->method('registry') ->with('current_order') ->willReturn($orderMock); $orderMock->expects($this->once()) ->method('getItemsCollection') ->willReturn($this->itemCollectionMock); $this->itemCollectionMock->expects($this->once()) ->method('getItems') ->willReturn($items); $this->assertEquals($items, $this->block->getItems()); } }