]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/Logger/SyslogLoggerTest.php
Move expand_acl to ACLFormatter::expand()
[friendica.git] / tests / src / Util / Logger / SyslogLoggerTest.php
1 <?php
2
3 namespace Friendica\Test\src\Util\Logger;
4
5 use Friendica\Util\Logger\SyslogLogger;
6 use Psr\Log\LogLevel;
7
8 class SyslogLoggerTest extends AbstractLoggerTest
9 {
10         /**
11          * @var SyslogLoggerWrapper
12          */
13         private $logger;
14
15         protected function setUp()
16         {
17                 parent::setUp();
18
19                 $this->introspection->shouldReceive('addClasses')->with([SyslogLogger::class]);
20         }
21
22         /**
23          * {@inheritdoc}
24          */
25         protected function getContent()
26         {
27                 return $this->logger->getContent();
28         }
29
30         /**
31          * {@inheritdoc}
32          */
33         protected function getInstance($level = LogLevel::DEBUG)
34         {
35                 $this->logger = new SyslogLoggerWrapper('test', $this->introspection, $level);
36
37                 return $this->logger;
38         }
39
40
41         /**
42          * Test when the minimum level is not valid
43          * @expectedException \InvalidArgumentException
44          * @expectedExceptionMessageRegExp /The level ".*" is not valid./
45          */
46         public function testWrongMinimumLevel()
47         {
48                 $logger = new SyslogLoggerWrapper('test', $this->introspection, 'NOPE');
49         }
50
51         /**
52          * Test when the minimum level is not valid
53          * @expectedException \InvalidArgumentException
54          * @expectedExceptionMessageRegExp /The level ".*" is not valid./
55          */
56         public function testWrongLogLevel()
57         {
58                 $logger = new SyslogLoggerWrapper('test', $this->introspection);
59
60                 $logger->log('NOPE', 'a test');
61         }
62
63         /**
64          * Test when the logfacility is wrong (string)
65          * @expectedException \UnexpectedValueException
66          * @expectedExceptionMessageRegExp /Can\'t open syslog for ident ".*" and facility ".*": .* /
67          */
68         public function testServerException()
69         {
70                 $logger = new SyslogLoggerWrapper('test', $this->introspection, LogLevel::DEBUG, null, 'a string');
71                 $logger->emergency('not working');
72         }
73
74         /**
75          * Test the close() method
76          */
77         public function testClose()
78         {
79                 $logger = new SyslogLoggerWrapper('test', $this->introspection);
80                 $logger->emergency('test');
81                 $logger->close();
82                 // Reopened itself
83                 $logger->emergency('test');
84         }
85 }