MailHandlerTest.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Logger;
  12. use Monolog\TestCase;
  13. class MailHandlerTest extends TestCase
  14. {
  15. /**
  16. * @covers Monolog\Handler\MailHandler::handleBatch
  17. */
  18. public function testHandleBatch()
  19. {
  20. $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
  21. $formatter->expects($this->once())
  22. ->method('formatBatch'); // Each record is formatted
  23. $handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
  24. $handler->expects($this->once())
  25. ->method('send');
  26. $handler->expects($this->never())
  27. ->method('write'); // write is for individual records
  28. $handler->setFormatter($formatter);
  29. $handler->handleBatch($this->getMultipleRecords());
  30. }
  31. /**
  32. * @covers Monolog\Handler\MailHandler::handleBatch
  33. */
  34. public function testHandleBatchNotSendsMailIfMessagesAreBelowLevel()
  35. {
  36. $records = array(
  37. $this->getRecord(Logger::DEBUG, 'debug message 1'),
  38. $this->getRecord(Logger::DEBUG, 'debug message 2'),
  39. $this->getRecord(Logger::INFO, 'information'),
  40. );
  41. $handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
  42. $handler->expects($this->never())
  43. ->method('send');
  44. $handler->setLevel(Logger::ERROR);
  45. $handler->handleBatch($records);
  46. }
  47. /**
  48. * @covers Monolog\Handler\MailHandler::write
  49. */
  50. public function testHandle()
  51. {
  52. $handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
  53. $handler->expects($this->once())
  54. ->method('send');
  55. $handler->handle($this->getRecord());
  56. }
  57. }