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-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;
|
|
|
|
|
2021-04-01 23:04:30 +02:00
|
|
|
protected function setUp(): void
|
2019-03-04 23:39:14 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->introspection->shouldReceive('addClasses')->with([SyslogLogger::class]);
|
2023-01-15 22:31:19 +01:00
|
|
|
$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)
|
|
|
|
{
|
2023-07-17 01:16:29 +02:00
|
|
|
$this->config->shouldReceive('get')->with('system', 'loglevel')->andReturn($level);
|
|
|
|
|
|
|
|
$loggerFactory = new SyslogLoggerFactoryWrapper($this->introspection, 'test');
|
|
|
|
$this->logger = $loggerFactory->create($this->config);
|
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);
|
2021-05-23 23:09:49 +02:00
|
|
|
$this->expectExceptionMessageMatches("/The level \".*\" is not valid./");
|
2023-07-17 01:16:29 +02:00
|
|
|
|
|
|
|
$logger = $this->getInstance('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);
|
2021-05-23 23:09:49 +02:00
|
|
|
$this->expectExceptionMessageMatches("/The level \".*\" is not valid./");
|
2020-10-18 20:31:57 +02:00
|
|
|
|
2023-07-17 01:16:29 +02:00
|
|
|
$logger = $this->getInstance();
|
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()
|
|
|
|
{
|
2023-07-17 01:16:29 +02:00
|
|
|
$logger = $this->getInstance();
|
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
|
|
|
}
|