Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReportModulesInfoTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class ReportModulesInfoTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $config;
24 
28  protected $collectMock;
29 
33  protected $systemFactoryMock;
34 
38  protected $systemModelMock;
39 
43  protected $jsonEncoderMock;
44 
50  protected function setUp()
51  {
52  $this->config = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Config::class)
53  ->disableOriginalConstructor()
54  ->setMethods(['isNewRelicEnabled'])
55  ->getMock();
56  $this->collectMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Module\Collect::class)
57  ->disableOriginalConstructor()
58  ->setMethods(['getModuleData'])
59  ->getMock();
60  $this->systemFactoryMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\SystemFactory::class)
61  ->disableOriginalConstructor()
62  ->setMethods(['create'])
63  ->getMock();
64  $this->systemModelMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\System::class)
65  ->disableOriginalConstructor()
66  ->getMock();
67  $this->jsonEncoderMock = $this->getMockBuilder(\Magento\Framework\Json\EncoderInterface::class)
68  ->getMock();
69 
70  $this->systemFactoryMock->expects($this->any())
71  ->method('create')
72  ->willReturn($this->systemModelMock);
73 
74  $this->jsonEncoderMock->expects($this->any())
75  ->method('encode')
76  ->willReturn('json_string');
77 
78  $this->model = new ReportModulesInfo(
79  $this->config,
80  $this->collectMock,
81  $this->systemFactoryMock,
82  $this->jsonEncoderMock
83  );
84  }
85 
92  {
93  $this->config->expects($this->once())
94  ->method('isNewRelicEnabled')
95  ->willReturn(false);
96 
97  $this->assertSame(
98  $this->model,
99  $this->model->report()
100  );
101  }
102 
108  public function testReportReportModulesInfo()
109  {
110  $this->config->expects($this->once())
111  ->method('isNewRelicEnabled')
112  ->willReturn(true);
113  $this->collectMock->expects($this->once())
114  ->method('getModuleData')
115  ->willReturn([
116  'installed' => '1',
117  'uninstalled' => '1',
118  'enabled' => '1',
119  'disabled' => '1',
120  'changes' => [
121  ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
122  ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
123  ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
124  ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
125  ]
126  ]);
127  $this->systemModelMock->expects($this->any())->method('setData')->willReturnSelf();
128  $this->systemModelMock->expects($this->any())->method('save')->willReturnSelf();
129 
130  $this->assertSame(
131  $this->model,
132  $this->model->report()
133  );
134  }
135 }