/** * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::executeInternal */ public function testExecute() { $creditmemoId = 2; $date = '2015-01-19_13-03-45'; $fileName = 'creditmemo2015-01-19_13-03-45.pdf'; $fileContents = 'pdf0123456789'; $this->prepareTestExecute($creditmemoId); $this->objectManagerMock->expects($this->any()) ->method('create') ->willReturnMap( [ ['Magento\Sales\Model\Order\Creditmemo', [], $this->creditmemoMock], ['Magento\Sales\Model\Order\Pdf\Creditmemo', [], $this->creditmemoPdfMock] ] ); $this->creditmemoRepositoryMock->expects($this->once()) ->method('get') ->with($creditmemoId) ->willReturn($this->creditmemoMock); $this->creditmemoPdfMock->expects($this->once()) ->method('getPdf') ->with([$this->creditmemoMock]) ->willReturn($this->pdfMock); $this->objectManagerMock->expects($this->once()) ->method('get') ->with('Magento\Framework\Stdlib\DateTime\DateTime') ->willReturn($this->dateTimeMock); $this->dateTimeMock->expects($this->once()) ->method('date') ->with('Y-m-d_H-i-s') ->willReturn($date); $this->pdfMock->expects($this->once()) ->method('render') ->willReturn($fileContents); $this->fileFactoryMock->expects($this->once()) ->method('create') ->with( $fileName, $fileContents, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, 'application/pdf' ) ->willReturn($this->responseMock); $this->assertInstanceOf( 'Magento\Framework\App\ResponseInterface', $this->printAction->executeInternal() ); }