TestHandlerTest.php 2.6 KB

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