Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReportSystemCacheFlushTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class ReportSystemCacheFlushTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $config;
24 
28  protected $systemFactory;
29 
33  protected $systemModel;
34 
38  protected $jsonEncoder;
39 
45  protected function setUp()
46  {
47  $this->config = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Config::class)
48  ->disableOriginalConstructor()
49  ->setMethods(['isNewRelicEnabled'])
50  ->getMock();
51  $this->systemFactory = $this->getMockBuilder(\Magento\NewRelicReporting\Model\SystemFactory::class)
52  ->disableOriginalConstructor()
53  ->setMethods(['create'])
54  ->getMock();
55  $this->systemModel = $this->getMockBuilder(\Magento\NewRelicReporting\Model\System::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->jsonEncoder = $this->getMockBuilder(\Magento\Framework\Json\EncoderInterface::class)
59  ->getMock();
60  $this->systemFactory->expects($this->any())
61  ->method('create')
62  ->willReturn($this->systemModel);
63 
64  $this->model = new ReportSystemCacheFlush(
65  $this->config,
66  $this->systemFactory,
67  $this->jsonEncoder
68  );
69  }
70 
76  public function testReportSystemCacheFlushModuleDisabledFromConfig()
77  {
79  $eventObserver = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82 
83  $this->config->expects($this->once())
84  ->method('isNewRelicEnabled')
85  ->willReturn(false);
86 
87  $this->model->execute($eventObserver);
88  }
89 
95  public function testReportSystemCacheFlush()
96  {
97  $testType = 'systemCacheFlush';
98  $testAction = 'JSON string';
99 
101  $eventObserver = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
102  ->disableOriginalConstructor()
103  ->getMock();
104 
105  $this->config->expects($this->once())
106  ->method('isNewRelicEnabled')
107  ->willReturn(true);
108  $this->jsonEncoder->expects($this->once())
109  ->method('encode')
110  ->willReturn($testAction);
111  $this->systemModel->expects($this->once())
112  ->method('setData')
113  ->with(['type' => $testType, 'action' => $testAction])
114  ->willReturnSelf();
115  $this->systemModel->expects($this->once())
116  ->method('save');
117 
118  $this->model->execute($eventObserver);
119  }
120 }