Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CronTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class CronTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $configMock;
24 
29 
33  protected $reportCountsMock;
34 
39 
40  protected function setUp()
41  {
42  $this->configMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Config::class)
43  ->setMethods(['isCronEnabled'])
44  ->disableOriginalConstructor()
45  ->getMock();
46 
47  $this->reportModulesInfoMock = $this->getMockBuilder(
48  \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo::class
49  )->disableOriginalConstructor()
50  ->getMock();
51 
52  $this->reportCountsMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Cron\ReportCounts::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55 
56  $this->reportNewRelicCronMock = $this->getMockBuilder(
57  \Magento\NewRelicReporting\Model\Cron\ReportNewRelicCron::class
58  )->disableOriginalConstructor()
59  ->getMock();
60 
61  $this->model = new Cron(
62  $this->configMock,
63  $this->reportModulesInfoMock,
64  $this->reportCountsMock,
65  $this->reportNewRelicCronMock
66  );
67  }
68 
75  {
76  $this->configMock->expects($this->once())
77  ->method('isCronEnabled')
78  ->willReturn(false);
79 
80  $this->assertSame(
81  $this->model,
82  $this->model->runCron()
83  );
84  }
85 
92  {
93  $this->configMock->expects($this->once())
94  ->method('isCronEnabled')
95  ->willReturn(true);
96 
97  $this->reportModulesInfoMock->expects($this->once())
98  ->method('report')
99  ->willReturnSelf();
100  $this->reportCountsMock->expects($this->once())
101  ->method('report')
102  ->willReturnSelf();
103  $this->reportNewRelicCronMock->expects($this->once())
104  ->method('report')
105  ->willReturnSelf();
106 
107  $this->assertSame(
108  $this->model,
109  $this->model->runCron()
110  );
111  }
112 }