TestHandlerTest.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /**
  14. * @covers Monolog\Handler\TestHandler
  15. */
  16. class TestHandlerTest extends TestCase
  17. {
  18. /**
  19. * @dataProvider methodProvider
  20. */
  21. public function testHandler($method, $level)
  22. {
  23. $handler = new TestHandler;
  24. $record = $this->getRecord($level, 'test'.$method);
  25. $this->assertFalse($handler->{'has'.$method}($record));
  26. $this->assertFalse($handler->{'has'.$method.'Records'}());
  27. $handler->handle($record);
  28. $this->assertFalse($handler->{'has'.$method}('bar'));
  29. $this->assertTrue($handler->{'has'.$method}($record));
  30. $this->assertTrue($handler->{'has'.$method}('test'.$method));
  31. $this->assertTrue($handler->{'has'.$method.'Records'}());
  32. $records = $handler->getRecords();
  33. unset($records[0]['formatted']);
  34. $this->assertEquals(array($record), $records);
  35. }
  36. public function methodProvider()
  37. {
  38. return array(
  39. array('Alert' , Logger::ALERT),
  40. array('Critical', Logger::CRITICAL),
  41. array('Error' , Logger::ERROR),
  42. array('Warning' , Logger::WARNING),
  43. array('Info' , Logger::INFO),
  44. array('Debug' , Logger::DEBUG),
  45. );
  46. }
  47. }