Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SyslogTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 use PHPUnit\Framework\TestCase;
15 use PHPUnit_Framework_MockObject_MockObject as Mock;
16 
20 class SyslogTest extends TestCase
21 {
25  private $model;
26 
30  private $scopeConfigMock;
31 
35  private $deploymentConfigMock;
36 
37  protected function setUp()
38  {
39  $this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
40  $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
41 
42  $this->model = new Syslog(
43  $this->scopeConfigMock,
44  $this->deploymentConfigMock,
45  'Magento'
46  );
47  }
48 
49  public function testIsHandling(): void
50  {
51  $record = [
52  'level' => Monolog::DEBUG,
53  ];
54 
55  $this->scopeConfigMock->expects($this->once())
56  ->method('getValue')
57  ->with(Syslog::CONFIG_PATH)
58  ->willReturn('1');
59  $this->deploymentConfigMock->expects($this->once())
60  ->method('isAvailable')
61  ->willReturn(true);
62 
63  $this->assertTrue(
64  $this->model->isHandling($record)
65  );
66  }
67 
68  public function testIsHandlingNotInstalled(): void
69  {
70  $record = [
71  'level' => Monolog::DEBUG,
72  ];
73 
74  $this->scopeConfigMock->expects($this->never())
75  ->method('getValue');
76  $this->deploymentConfigMock->expects($this->once())
77  ->method('isAvailable')
78  ->willReturn(false);
79 
80  $this->assertFalse(
81  $this->model->isHandling($record)
82  );
83  }
84 
85  public function testIsHandlingDisabled(): void
86  {
87  $record = [
88  'level' => Monolog::DEBUG,
89  ];
90 
91  $this->scopeConfigMock->expects($this->once())
92  ->method('getValue')
93  ->with(Syslog::CONFIG_PATH)
94  ->willReturn('0');
95  $this->deploymentConfigMock->expects($this->once())
96  ->method('isAvailable')
97  ->willReturn(true);
98 
99  $this->assertFalse(
100  $this->model->isHandling($record)
101  );
102  }
103 }