123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?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
- {
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::__construct
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- */
- 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);
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- */
- 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());
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- * @covers Monolog\Handler\FingersCrossedHandler::reset
- */
- public function testHandleRestartBufferingAfterReset()
- {
- $test = new TestHandler();
- $handler = new FingersCrossedHandler($test);
- $handler->handle($this->getRecord(Logger::WARNING));
- $handler->handle($this->getRecord(Logger::DEBUG));
- $handler->reset();
- $handler->handle($this->getRecord(Logger::INFO));
- $this->assertTrue($test->hasWarningRecords());
- $this->assertTrue($test->hasDebugRecords());
- $this->assertFalse($test->hasInfoRecords());
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- */
- public function testHandleRestartBufferingAfterBeingTriggeredWhenStopBufferingIsDisabled()
- {
- $test = new TestHandler();
- $handler = new FingersCrossedHandler($test, Logger::WARNING, 0, false, false);
- $handler->handle($this->getRecord(Logger::DEBUG));
- $handler->handle($this->getRecord(Logger::WARNING));
- $handler->handle($this->getRecord(Logger::INFO));
- $this->assertTrue($test->hasWarningRecords());
- $this->assertTrue($test->hasDebugRecords());
- $this->assertFalse($test->hasInfoRecords());
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- */
- 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());
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- */
- 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);
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::handle
- * @expectedException RuntimeException
- */
- public function testHandleWithBadCallbackThrowsException()
- {
- $handler = new FingersCrossedHandler(function($record, $handler) {
- return 'foo';
- });
- $handler->handle($this->getRecord(Logger::WARNING));
- }
-
- /**
- * @covers Monolog\Handler\FingersCrossedHandler::isHandling
- */
- public function testIsHandlingAlways()
- {
- $test = new TestHandler();
- $handler = new FingersCrossedHandler($test, Logger::ERROR);
- $this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG)));
- }
- }
|