MailHandlerTest.php 1.7 KB

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