Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckConfigTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class CheckConfigTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $config;
24 
28  protected $newRelicWrapper;
29 
33  protected $messageManager;
34 
40  protected function setUp()
41  {
42  $this->config = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Config::class)
43  ->disableOriginalConstructor()
44  ->setMethods(['isNewRelicEnabled', 'disableModule'])
45  ->getMock();
46  $this->newRelicWrapper = $this->getMockBuilder(\Magento\NewRelicReporting\Model\NewRelicWrapper::class)
47  ->disableOriginalConstructor()
48  ->setMethods(['isExtensionInstalled'])
49  ->getMock();
50  $this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
51  ->disableOriginalConstructor()
52  ->getMock();
53 
54  $this->model = new CheckConfig(
55  $this->config,
56  $this->newRelicWrapper,
57  $this->messageManager
58  );
59  }
60 
66  public function testCheckConfigModuleDisabledFromConfig()
67  {
69  $eventObserver = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72 
73  $this->config->expects($this->once())
74  ->method('isNewRelicEnabled')
75  ->willReturn(false);
76 
77  $this->model->execute($eventObserver);
78  }
79 
85  public function testCheckConfigExtensionNotInstalled()
86  {
88  $eventObserver = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
89  ->disableOriginalConstructor()
90  ->getMock();
91 
92  $this->config->expects($this->once())
93  ->method('isNewRelicEnabled')
94  ->willReturn(true);
95  $this->newRelicWrapper->expects($this->once())
96  ->method('isExtensionInstalled')
97  ->willReturn(true);
98 
99  $this->model->execute($eventObserver);
100  }
101 
107  public function testCheckConfig()
108  {
110  $eventObserver = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
111  ->disableOriginalConstructor()
112  ->getMock();
113 
114  $this->config->expects($this->once())
115  ->method('isNewRelicEnabled')
116  ->willReturn(true);
117  $this->newRelicWrapper->expects($this->once())
118  ->method('isExtensionInstalled')
119  ->willReturn(false);
120  $this->config->expects($this->once())
121  ->method('disableModule');
122  $this->messageManager->expects($this->once())
123  ->method('addError');
124 
125  $this->model->execute($eventObserver);
126  }
127 }