friendica/tests/src/Core/Logger/SyslogLoggerTest.php

104 lines
2.8 KiB
PHP
Raw Normal View History

2019-03-04 23:39:14 +01:00
<?php
2020-02-09 15:45:36 +01:00
/**
2023-01-01 15:36:24 +01:00
* @copyright Copyright (C) 2010-2023, the Friendica project
2020-02-09 15:45:36 +01:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2019-03-04 23:39:14 +01:00
2021-10-23 12:22:27 +02:00
namespace Friendica\Test\src\Core\Logger;
2019-03-04 23:39:14 +01:00
2021-10-23 12:22:27 +02:00
use Friendica\Core\Logger\Exception\LoggerArgumentException;
use Friendica\Core\Logger\Exception\LoggerException;
2021-10-29 08:03:59 +02:00
use Friendica\Core\Logger\Exception\LogLevelException;
2021-10-23 12:22:27 +02:00
use Friendica\Core\Logger\Type\SyslogLogger;
2019-03-04 23:39:14 +01:00
use Psr\Log\LogLevel;
class SyslogLoggerTest extends AbstractLoggerTest
{
/**
* @var SyslogLoggerWrapper
*/
private $logger;
protected function setUp(): void
2019-03-04 23:39:14 +01:00
{
parent::setUp();
$this->introspection->shouldReceive('addClasses')->with([SyslogLogger::class]);
$this->config->shouldReceive('get')->with('system', 'syslog_flags')->andReturn(SyslogLogger::DEFAULT_FLAGS)
->once();
$this->config->shouldReceive('get')->with('system', 'syslog_facility')
->andReturn(SyslogLogger::DEFAULT_FACILITY)->once();
2019-03-04 23:39:14 +01:00
}
/**
* {@inheritdoc}
*/
protected function getContent()
{
return $this->logger->getContent();
}
/**
* {@inheritdoc}
*/
protected function getInstance($level = LogLevel::DEBUG)
{
$this->logger = new SyslogLoggerWrapper('test', $this->config, $this->introspection, $level);
2019-03-04 23:39:14 +01:00
return $this->logger;
}
/**
* Test when the minimum level is not valid
*/
public function testWrongMinimumLevel()
{
2021-10-29 08:03:59 +02:00
$this->expectException(LogLevelException::class);
$this->expectExceptionMessageMatches("/The level \".*\" is not valid./");
$logger = new SyslogLoggerWrapper('test', $this->config, $this->introspection, 'NOPE');
2019-03-04 23:39:14 +01:00
}
/**
* Test when the minimum level is not valid
*/
public function testWrongLogLevel()
{
2021-10-29 08:03:59 +02:00
$this->expectException(LogLevelException::class);
$this->expectExceptionMessageMatches("/The level \".*\" is not valid./");
$logger = new SyslogLoggerWrapper('test', $this->config, $this->introspection);
2019-03-04 23:39:14 +01:00
$logger->log('NOPE', 'a test');
}
2019-03-04 23:49:37 +01:00
2019-03-05 00:11:02 +01:00
/**
* Test the close() method
2021-04-01 21:19:45 +02:00
* @doesNotPerformAssertions
2019-03-05 00:11:02 +01:00
*/
public function testClose()
{
$logger = new SyslogLoggerWrapper('test', $this->config, $this->introspection);
2019-03-05 00:11:02 +01:00
$logger->emergency('test');
$logger->close();
// Reopened itself
$logger->emergency('test');
}
2019-03-04 23:39:14 +01:00
}