2018-10-20 15:00:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Logging\Tests;
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
use InvalidArgumentException;
|
2018-07-04 01:55:31 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2018-10-20 15:00:08 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Logging\MonologErrorHandler;
|
|
|
|
|
|
|
|
class MonologErrorHandlerTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testStartThrowsExceptionWithoutLoggerDefined()
|
|
|
|
{
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessageMatches('/No Logger properties passed to MonologErrorHandler/');
|
2018-10-20 15:00:08 +02:00
|
|
|
$handler = new MonologErrorHandler();
|
|
|
|
$handler->start();
|
|
|
|
}
|
2018-07-04 01:55:31 +02:00
|
|
|
|
|
|
|
public function testSetLoggerResetsStack()
|
|
|
|
{
|
|
|
|
/** @var LoggerInterface $logger */
|
|
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
|
|
|
|
|
|
$handler = new MonologErrorHandler();
|
|
|
|
$handler->pushLogger($logger)->pushLogger($logger);
|
|
|
|
$this->assertCount(2, $handler->getLoggers(), 'Loggers are pushed to the stack');
|
|
|
|
|
|
|
|
$handler->setLogger($logger);
|
|
|
|
$this->assertCount(1, $handler->getLoggers(), 'setLogger resets stack and pushes');
|
|
|
|
|
|
|
|
$handler->setLoggers([]);
|
|
|
|
$this->assertCount(0, $handler->getLoggers(), 'setLoggers overwrites all configured loggers');
|
|
|
|
}
|
2018-10-20 15:00:08 +02:00
|
|
|
}
|