TestHandlerTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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), 'has'.$method);
  26. $this->assertFalse($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains');
  27. $this->assertFalse($handler->{'has'.$method.'Records'}(), 'has'.$method.'Records');
  28. $handler->handle($record);
  29. $this->assertFalse($handler->{'has'.$method}('bar'), 'has'.$method);
  30. $this->assertTrue($handler->{'has'.$method}($record), 'has'.$method);
  31. $this->assertTrue($handler->{'has'.$method}('test'.$method), 'has'.$method);
  32. $this->assertTrue($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains');
  33. $this->assertTrue($handler->{'has'.$method.'Records'}(), 'has'.$method.'Records');
  34. $records = $handler->getRecords();
  35. unset($records[0]['formatted']);
  36. $this->assertEquals(array($record), $records);
  37. }
  38. public function methodProvider()
  39. {
  40. return array(
  41. array('Emergency', Logger::EMERGENCY),
  42. array('Alert' , Logger::ALERT),
  43. array('Critical' , Logger::CRITICAL),
  44. array('Error' , Logger::ERROR),
  45. array('Warning' , Logger::WARNING),
  46. array('Info' , Logger::INFO),
  47. array('Notice' , Logger::NOTICE),
  48. array('Debug' , Logger::DEBUG),
  49. );
  50. }
  51. }