Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PdfDocumentsMassActionTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class PdfDocumentsMassActionTest extends \PHPUnit\Framework\TestCase
12 {
16  private $controller;
17 
21  private $resultRedirect;
22 
26  private $messageManager;
27 
31  private $orderCollectionFactoryMock;
32 
36  private $orderCollectionMock;
37 
41  private $filterMock;
42 
46  protected function setUp()
47  {
48  $objectManagerHelper = new ObjectManagerHelper($this);
49 
50  $this->messageManager = $this->createPartialMock(
51  \Magento\Framework\Message\Manager::class,
52  ['addSuccessMessage', 'addErrorMessage']
53  );
54 
55  $this->orderCollectionMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Order\Collection::class);
56  $this->filterMock = $this->createMock(\Magento\Ui\Component\MassAction\Filter::class);
57 
58  $this->orderCollectionFactoryMock = $this->createPartialMock(
59  \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class,
60  ['create']
61  );
62 
63  $this->orderCollectionFactoryMock
64  ->expects($this->once())
65  ->method('create')
66  ->willReturn($this->orderCollectionMock);
67  $this->resultRedirect = $this->createMock(\Magento\Backend\Model\View\Result\Redirect::class);
68  $resultRedirectFactory = $this->createMock(\Magento\Framework\Controller\ResultFactory::class);
69  $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
70  $this->controller = $objectManagerHelper->getObject(
71  \Magento\Sales\Controller\Adminhtml\Order\Pdfinvoices::class,
72  [
73  'filter' => $this->filterMock,
74  'resultFactory' => $resultRedirectFactory,
75  'messageManager' => $this->messageManager
76  ]
77  );
78  $objectManagerHelper
79  ->setBackwardCompatibleProperty(
80  $this->controller,
81  'orderCollectionFactory',
82  $this->orderCollectionFactoryMock
83  );
84  }
85 
89  public function testExecute()
90  {
91  $exception = new \Exception();
92  $this->filterMock
93  ->expects($this->once())
94  ->method('getCollection')
95  ->with($this->orderCollectionMock)
96  ->willThrowException($exception);
97  $this->messageManager->expects($this->once())->method('addErrorMessage');
98 
99  $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
100  $this->controller->execute($exception);
101  }
102 }