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()
|
|
|
|
{
|
2022-11-28 07:16:31 +01:00
|
|
|
if (Deprecation::isEnabled()) {
|
|
|
|
$this->markTestSkipped('Test calls deprecated code');
|
|
|
|
}
|
2018-07-04 01:55:31 +02:00
|
|
|
/** @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->setLoggers([]);
|
|
|
|
$this->assertCount(0, $handler->getLoggers(), 'setLoggers overwrites all configured loggers');
|
|
|
|
}
|
2018-10-20 15:00:08 +02:00
|
|
|
}
|