AbstractHandlerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Processor\WebProcessor;
  14. class AbstractHandlerTest extends TestCase
  15. {
  16. /**
  17. * @covers Monolog\Handler\AbstractHandler::__construct
  18. * @covers Monolog\Handler\AbstractHandler::getLevel
  19. * @covers Monolog\Handler\AbstractHandler::setLevel
  20. * @covers Monolog\Handler\AbstractHandler::getBubble
  21. * @covers Monolog\Handler\AbstractHandler::setBubble
  22. */
  23. public function testConstructAndGetSet()
  24. {
  25. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
  26. $this->assertEquals(Logger::WARNING, $handler->getLevel());
  27. $this->assertEquals(false, $handler->getBubble());
  28. $handler->setLevel(Logger::ERROR);
  29. $handler->setBubble(true);
  30. $this->assertEquals(Logger::ERROR, $handler->getLevel());
  31. $this->assertEquals(true, $handler->getBubble());
  32. }
  33. /**
  34. * @covers Monolog\Handler\AbstractHandler::handleBatch
  35. */
  36. public function testHandleBatch()
  37. {
  38. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
  39. $handler->expects($this->exactly(2))
  40. ->method('handle');
  41. $handler->handleBatch(array($this->getRecord(), $this->getRecord()));
  42. }
  43. /**
  44. * @covers Monolog\Handler\AbstractHandler::isHandling
  45. */
  46. public function testIsHandling()
  47. {
  48. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
  49. $this->assertTrue($handler->isHandling($this->getRecord()));
  50. $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
  51. }
  52. /**
  53. * @covers Monolog\Handler\AbstractHandler::__construct
  54. */
  55. public function testHandlesPsrStyleLevels()
  56. {
  57. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array('warning', false));
  58. $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
  59. $handler->setLevel('debug');
  60. $this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG)));
  61. }
  62. }