Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RefreshStatisticsTest.php
Go to the documentation of this file.
1 <?php
8 
12 class RefreshStatisticsTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $resultRedirect;
18 
23 
27  protected $request;
28 
32  protected $response;
33 
37  protected $messageManager;
38 
42  protected $order;
43 
47  protected $objectManager;
48 
53 
57  protected $context;
58 
59  protected function setUp()
60  {
61  $reportTypes = [
62  'sales' => \Magento\Sales\Model\ResourceModel\Report\Order::class
63  ];
64 
65  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
66 
67  $this->resultRedirectFactory = $this->createPartialMock(
68  \Magento\Backend\Model\View\Result\RedirectFactory::class,
69  ['create']
70  );
71  $this->resultRedirect = $this->createMock(\Magento\Backend\Model\View\Result\Redirect::class);
72 
73  $this->request = $this->createMock(\Magento\Framework\App\RequestInterface::class);
74  $this->response = $this->createPartialMock(
75  \Magento\Framework\App\ResponseInterface::class,
76  ['setRedirect', 'sendResponse']
77  );
78 
79  $this->messageManager = $this->createMock(\Magento\Framework\Message\Manager::class);
80 
81  $this->order = $this->createMock(\Magento\Sales\Model\ResourceModel\Report\Order::class);
82 
83  $this->objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
84 
85  $this->context = $this->createMock(\Magento\Backend\App\Action\Context::class);
86  $this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
87  $this->context->expects($this->once())->method('getResponse')->willReturn($this->response);
88  $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager);
89  $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager);
90  $this->context->expects($this->once())
91  ->method('getResultRedirectFactory')
92  ->willReturn($this->resultRedirectFactory);
93 
94  $this->refreshStatisticsController = $objectManagerHelper->getObject(
95  \Magento\Backend\Controller\Adminhtml\Dashboard\RefreshStatistics::class,
96  [
97  'context' => $this->context,
98  'reportTypes' => $reportTypes
99  ]
100  );
101  }
102 
103  public function testExecute()
104  {
105  $path = '*/*';
106 
107  $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
108 
109  $this->messageManager->expects($this->once())
110  ->method('addSuccessMessage')
111  ->with(__('We updated lifetime statistic.'));
112 
113  $this->objectManager->expects($this->any())
114  ->method('create')
115  ->with(\Magento\Sales\Model\ResourceModel\Report\Order::class)
116  ->willReturn($this->order);
117 
118  $this->resultRedirect->expects($this->once())
119  ->method('setPath')
120  ->with($path)
121  ->willReturnSelf();
122 
123  $this->assertInstanceOf(
124  \Magento\Backend\Model\View\Result\Redirect::class,
125  $this->refreshStatisticsController->execute()
126  );
127  }
128 }
__()
Definition: __.php:13