Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AggregateSalesReportInvoicedDataTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Sales\Model\CronJob\AggregateSalesReportInvoicedData;
9 
13 class AggregateSalesReportInvoicedDataTest extends \PHPUnit\Framework\TestCase
14 {
19 
23  protected $localeDateMock;
24 
29 
33  protected $observer;
34 
35  protected function setUp()
36  {
37  $this->localeResolverMock = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  $this->invoicedFactoryMock = $this->getMockBuilder(
42  \Magento\Sales\Model\ResourceModel\Report\InvoicedFactory::class
43  )
44  ->disableOriginalConstructor()
45  ->setMethods(['create'])
46  ->getMock();
47  $this->localeDateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50 
51  $this->observer = new AggregateSalesReportInvoicedData(
52  $this->localeResolverMock,
53  $this->localeDateMock,
54  $this->invoicedFactoryMock
55  );
56  }
57 
58  public function testExecute()
59  {
60  $date = $this->setupAggregate();
61  $invoicedMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Report\Invoiced::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64  $invoicedMock->expects($this->once())
65  ->method('aggregate')
66  ->with($date);
67  $this->invoicedFactoryMock->expects($this->once())
68  ->method('create')
69  ->will($this->returnValue($invoicedMock));
70  $this->observer->execute();
71  }
72 
78  protected function setupAggregate()
79  {
80  $this->localeResolverMock->expects($this->once())
81  ->method('emulate')
82  ->with(0);
83  $this->localeResolverMock->expects($this->once())
84  ->method('revert');
85 
86  $date = (new \DateTime())->sub(new \DateInterval('PT25H'));
87  $this->localeDateMock->expects($this->once())
88  ->method('date')
89  ->will($this->returnValue($date));
90 
91  return $date;
92  }
93 }