TestHandlerTest.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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('Emergency', Logger::EMERGENCY),
  40. array('Alert' , Logger::ALERT),
  41. array('Critical' , Logger::CRITICAL),
  42. array('Error' , Logger::ERROR),
  43. array('Warning' , Logger::WARNING),
  44. array('Info' , Logger::INFO),
  45. array('Notice' , Logger::NOTICE),
  46. array('Debug' , Logger::DEBUG),
  47. );
  48. }
  49. }