1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-17 14:46:33 +02:00
Files
php-monolog/tests/Monolog/Handler/FingersCrossedHandlerTest.php
Christophe Coevoet 3cb3dbdc8f Made the write method protected
Tests are not a good reason to make it public.
2011-04-06 13:22:06 +02:00

81 lines
2.7 KiB
PHP

<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\TestCase;
use Monolog\Logger;
class FingersCrossedHandlerTest extends TestCase
{
public function testHandleBuffers()
{
$test = new TestHandler();
$handler = new FingersCrossedHandler($test);
$handler->handle($this->getRecord(Logger::DEBUG));
$handler->handle($this->getRecord(Logger::INFO));
$this->assertFalse($test->hasDebugRecords());
$this->assertFalse($test->hasInfoRecords());
$handler->handle($this->getRecord(Logger::WARNING));
$this->assertTrue($test->hasInfoRecords());
$this->assertTrue(count($test->getRecords()) === 3);
}
public function testHandleStopsBufferingAfterTrigger()
{
$test = new TestHandler();
$handler = new FingersCrossedHandler($test);
$handler->handle($this->getRecord(Logger::WARNING));
$handler->handle($this->getRecord(Logger::DEBUG));
$this->assertTrue($test->hasWarningRecords());
$this->assertTrue($test->hasDebugRecords());
}
public function testHandleBufferLimit()
{
$test = new TestHandler();
$handler = new FingersCrossedHandler($test, Logger::WARNING, 2);
$handler->handle($this->getRecord(Logger::DEBUG));
$handler->handle($this->getRecord(Logger::DEBUG));
$handler->handle($this->getRecord(Logger::INFO));
$handler->handle($this->getRecord(Logger::WARNING));
$this->assertTrue($test->hasWarningRecords());
$this->assertTrue($test->hasInfoRecords());
$this->assertFalse($test->hasDebugRecords());
}
public function testHandleWithCallback()
{
$test = new TestHandler();
$handler = new FingersCrossedHandler(function($record, $handler) use ($test) {
return $test;
});
$handler->handle($this->getRecord(Logger::DEBUG));
$handler->handle($this->getRecord(Logger::INFO));
$this->assertFalse($test->hasDebugRecords());
$this->assertFalse($test->hasInfoRecords());
$handler->handle($this->getRecord(Logger::WARNING));
$this->assertTrue($test->hasInfoRecords());
$this->assertTrue(count($test->getRecords()) === 3);
}
/**
* @expectedException RuntimeException
*/
public function testHandleWithBadCallbackThrowsException()
{
$handler = new FingersCrossedHandler(function($record, $handler) {
return 'foo';
});
$handler->handle($this->getRecord(Logger::WARNING));
}
}