localeResolverMock = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class) ->disableOriginalConstructor() ->getMock(); $this->invoicedFactoryMock = $this->getMockBuilder( \Magento\Sales\Model\ResourceModel\Report\InvoicedFactory::class ) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $this->localeDateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class) ->disableOriginalConstructor() ->getMock(); $this->observer = new AggregateSalesReportInvoicedData( $this->localeResolverMock, $this->localeDateMock, $this->invoicedFactoryMock ); } public function testExecute() { $date = $this->setupAggregate(); $invoicedMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Report\Invoiced::class) ->disableOriginalConstructor() ->getMock(); $invoicedMock->expects($this->once()) ->method('aggregate') ->with($date); $this->invoicedFactoryMock->expects($this->once()) ->method('create') ->will($this->returnValue($invoicedMock)); $this->observer->execute(); } /** * Set up aggregate * * @return \DateTime */ protected function setupAggregate() { $this->localeResolverMock->expects($this->once()) ->method('emulate') ->with(0); $this->localeResolverMock->expects($this->once()) ->method('revert'); $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once()) ->method('date') ->will($this->returnValue($date)); return $date; } }