ErrorLogHandlerTest.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Monolog\Handler;
  3. use Monolog\TestCase;
  4. use Monolog\Logger;
  5. function error_log()
  6. {
  7. $GLOBALS['error_log'] = func_get_args();
  8. }
  9. class ErrorLogHandlerTest extends TestCase
  10. {
  11. protected function setUp()
  12. {
  13. $GLOBALS['error_log'] = array();
  14. }
  15. /**
  16. * @covers Monolog\Handler\ErrorLogHandler::__construct
  17. * @expectedException InvalidArgumentException
  18. * @expectedExceptionMessage The given message type "42" is not supported
  19. */
  20. public function testShouldNotAcceptAnInvalidTypeOnContructor()
  21. {
  22. new ErrorLogHandler(42);
  23. }
  24. /**
  25. * @covers Monolog\Handler\ErrorLogHandler::write
  26. */
  27. public function testShouldLogMessagesUsingErrorLogFuncion()
  28. {
  29. $type = ErrorLogHandler::OPERATING_SYSTEM;
  30. $handler = new ErrorLogHandler($type);
  31. $handler->handle($this->getRecord(Logger::ERROR));
  32. $this->assertStringMatchesFormat('[%s] test.ERROR: test [] []', $GLOBALS['error_log'][0]);
  33. $this->assertSame($GLOBALS['error_log'][1], $type);
  34. }
  35. }