AbstractHandlerTest.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. use Monolog\Formatter\LineFormatter;
  14. use Monolog\Processor\WebProcessor;
  15. class AbstractHandlerTest extends TestCase
  16. {
  17. /**
  18. * @covers Monolog\Handler\AbstractHandler::__construct
  19. * @covers Monolog\Handler\AbstractHandler::getLevel
  20. * @covers Monolog\Handler\AbstractHandler::setLevel
  21. * @covers Monolog\Handler\AbstractHandler::getBubble
  22. * @covers Monolog\Handler\AbstractHandler::setBubble
  23. * @covers Monolog\Handler\AbstractHandler::getFormatter
  24. * @covers Monolog\Handler\AbstractHandler::setFormatter
  25. */
  26. public function testConstructAndGetSet()
  27. {
  28. $handler = new TestHandler(Logger::WARNING, false);
  29. $this->assertEquals(Logger::WARNING, $handler->getLevel());
  30. $this->assertEquals(false, $handler->getBubble());
  31. $handler->setLevel(Logger::ERROR);
  32. $handler->setBubble(true);
  33. $handler->setFormatter($formatter = new LineFormatter);
  34. $this->assertEquals(Logger::ERROR, $handler->getLevel());
  35. $this->assertEquals(true, $handler->getBubble());
  36. $this->assertEquals($formatter, $handler->getFormatter());
  37. }
  38. /**
  39. * @covers Monolog\Handler\AbstractHandler::handleBatch
  40. */
  41. public function testHandleBatch()
  42. {
  43. $handler = new TestHandler();
  44. $handler->handleBatch(array($this->getRecord(), $this->getRecord()));
  45. $this->assertEquals(2, count($handler->getRecords()));
  46. }
  47. /**
  48. * @covers Monolog\Handler\AbstractHandler::isHandling
  49. */
  50. public function testIsHandling()
  51. {
  52. $handler = new TestHandler(Logger::WARNING, false);
  53. $this->assertTrue($handler->isHandling($this->getRecord()));
  54. $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
  55. }
  56. /**
  57. * @covers Monolog\Handler\AbstractHandler::getFormatter
  58. * @covers Monolog\Handler\AbstractHandler::getDefaultFormatter
  59. */
  60. public function testGetFormatterInitializesDefault()
  61. {
  62. $handler = new TestHandler();
  63. $this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter());
  64. }
  65. /**
  66. * @covers Monolog\Handler\AbstractHandler::pushProcessor
  67. * @covers Monolog\Handler\AbstractHandler::popProcessor
  68. * @expectedException LogicException
  69. */
  70. public function testPushPopProcessor()
  71. {
  72. $logger = new TestHandler();
  73. $processor1 = new WebProcessor;
  74. $processor2 = new WebProcessor;
  75. $logger->pushProcessor($processor1);
  76. $logger->pushProcessor($processor2);
  77. $this->assertEquals($processor2, $logger->popProcessor());
  78. $this->assertEquals($processor1, $logger->popProcessor());
  79. $logger->popProcessor();
  80. }
  81. }