TestHandlerTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php declare(strict_types=1);
  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([$record], $records);
  45. }
  46. public function methodProvider()
  47. {
  48. return [
  49. ['Emergency', Logger::EMERGENCY],
  50. ['Alert' , Logger::ALERT],
  51. ['Critical' , Logger::CRITICAL],
  52. ['Error' , Logger::ERROR],
  53. ['Warning' , Logger::WARNING],
  54. ['Info' , Logger::INFO],
  55. ['Notice' , Logger::NOTICE],
  56. ['Debug' , Logger::DEBUG],
  57. ];
  58. }
  59. }