GroupHandlerTest.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 GroupHandlerTest extends TestCase
  14. {
  15. /**
  16. * @covers Monolog\Handler\GroupHandler::__construct
  17. * @expectedException InvalidArgumentException
  18. */
  19. public function testConstructorOnlyTakesHandler()
  20. {
  21. new GroupHandler(array(new TestHandler(), "foo"));
  22. }
  23. /**
  24. * @covers Monolog\Handler\GroupHandler::__construct
  25. * @covers Monolog\Handler\GroupHandler::handle
  26. */
  27. public function testHandle()
  28. {
  29. $testHandlers = array(new TestHandler(), new TestHandler());
  30. $handler = new GroupHandler($testHandlers);
  31. $handler->handle($this->getRecord(Logger::DEBUG));
  32. $handler->handle($this->getRecord(Logger::INFO));
  33. foreach ($testHandlers as $test) {
  34. $this->assertTrue($test->hasDebugRecords());
  35. $this->assertTrue($test->hasInfoRecords());
  36. $this->assertTrue(count($test->getRecords()) === 2);
  37. }
  38. }
  39. /**
  40. * @covers Monolog\Handler\GroupHandler::handleBatch
  41. */
  42. public function testHandleBatch()
  43. {
  44. $testHandlers = array(new TestHandler(), new TestHandler());
  45. $handler = new GroupHandler($testHandlers);
  46. $handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO)));
  47. foreach ($testHandlers as $test) {
  48. $this->assertTrue($test->hasDebugRecords());
  49. $this->assertTrue($test->hasInfoRecords());
  50. $this->assertTrue(count($test->getRecords()) === 2);
  51. }
  52. }
  53. /**
  54. * @covers Monolog\Handler\GroupHandler::isHandling
  55. */
  56. public function testIsHandling()
  57. {
  58. $testHandlers = array(new TestHandler(Logger::ERROR), new TestHandler(Logger::WARNING));
  59. $handler = new GroupHandler($testHandlers);
  60. $this->assertTrue($handler->isHandling($this->getRecord(Logger::ERROR)));
  61. $this->assertTrue($handler->isHandling($this->getRecord(Logger::WARNING)));
  62. $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
  63. }
  64. }