2018-10-20 15:00:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Logging\Tests;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
2018-11-13 10:09:33 +01:00
|
|
|
* @expectedExceptionMessageRegExp /No Logger properties passed to MonologErrorHandler/
|
2018-10-20 15:00:08 +02:00
|
|
|
*/
|
|
|
|
public function testStartThrowsExceptionWithoutLoggerDefined()
|
|
|
|
{
|
|
|
|
$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
|
|
|
}
|