AbstractHandlerTest.php 2.3 KB

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