silverstripe-framework/tests/php/Logging/MonologErrorHandlerTest.php

40 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace SilverStripe\Logging\Tests;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
2022-11-15 06:20:54 +01:00
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Logging\MonologErrorHandler;
class MonologErrorHandlerTest extends SapphireTest
{
public function testStartThrowsExceptionWithoutLoggerDefined()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/No Logger properties passed to MonologErrorHandler/');
$handler = new MonologErrorHandler();
$handler->start();
}
public function testSetLoggerResetsStack()
{
2022-11-28 07:16:31 +01:00
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @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');
2022-11-28 07:16:31 +01:00
$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');
}
}