TestHandlerTest.php 2.4 KB

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