BufferHandlerTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\TestCase;
  12. use Monolog\Logger;
  13. class BufferHandlerTest extends TestCase
  14. {
  15. public function testHandleBuffers()
  16. {
  17. $test = new TestHandler();
  18. $handler = new BufferHandler($test);
  19. $handler->handle($this->getRecord(Logger::DEBUG));
  20. $handler->handle($this->getRecord(Logger::INFO));
  21. $this->assertFalse($test->hasDebugRecords());
  22. $this->assertFalse($test->hasInfoRecords());
  23. $handler->close();
  24. $this->assertTrue($test->hasInfoRecords());
  25. $this->assertTrue(count($test->getRecords()) === 2);
  26. }
  27. public function testDestructPropagatesRecords()
  28. {
  29. $test = new TestHandler();
  30. $handler = new BufferHandler($test);
  31. $handler->handle($this->getRecord(Logger::WARNING));
  32. $handler->handle($this->getRecord(Logger::DEBUG));
  33. unset($handler);
  34. $this->assertTrue($test->hasWarningRecords());
  35. $this->assertTrue($test->hasDebugRecords());
  36. }
  37. public function testHandleBufferLimit()
  38. {
  39. $test = new TestHandler();
  40. $handler = new BufferHandler($test, 2);
  41. $handler->handle($this->getRecord(Logger::DEBUG));
  42. $handler->handle($this->getRecord(Logger::DEBUG));
  43. $handler->handle($this->getRecord(Logger::INFO));
  44. $handler->handle($this->getRecord(Logger::WARNING));
  45. $handler->close();
  46. $this->assertTrue($test->hasWarningRecords());
  47. $this->assertTrue($test->hasInfoRecords());
  48. $this->assertFalse($test->hasDebugRecords());
  49. }
  50. }