MailHandlerTest.php 1.9 KB

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