IntrospectionProcessorTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Acme;
  11. class Tester
  12. {
  13. public function test($handler, $record)
  14. {
  15. $handler->handle($record);
  16. }
  17. }
  18. function tester($handler, $record)
  19. {
  20. $handler->handle($record);
  21. }
  22. namespace Monolog\Processor;
  23. use Monolog\Level;
  24. use Monolog\Handler\TestHandler;
  25. class IntrospectionProcessorTest extends \Monolog\Test\MonologTestCase
  26. {
  27. public function getHandler()
  28. {
  29. $processor = new IntrospectionProcessor();
  30. $handler = new TestHandler();
  31. $handler->pushProcessor($processor);
  32. return $handler;
  33. }
  34. public function testProcessorFromClass()
  35. {
  36. $handler = $this->getHandler();
  37. $tester = new \Acme\Tester;
  38. $tester->test($handler, $this->getRecord());
  39. list($record) = $handler->getRecords();
  40. $this->assertEquals(__FILE__, $record->extra['file']);
  41. $this->assertEquals(18, $record->extra['line']);
  42. $this->assertEquals('Acme\Tester', $record->extra['class']);
  43. $this->assertEquals('test', $record->extra['function']);
  44. }
  45. public function testProcessorFromFunc()
  46. {
  47. $handler = $this->getHandler();
  48. \Acme\tester($handler, $this->getRecord());
  49. list($record) = $handler->getRecords();
  50. $this->assertEquals(__FILE__, $record->extra['file']);
  51. $this->assertEquals(24, $record->extra['line']);
  52. $this->assertEquals(null, $record->extra['class']);
  53. $this->assertEquals('Acme\tester', $record->extra['function']);
  54. }
  55. public function testLevelTooLow()
  56. {
  57. $input = $this->getRecord(Level::Debug);
  58. $expected = clone $input;
  59. $processor = new IntrospectionProcessor(Level::Critical);
  60. $actual = $processor($input);
  61. $this->assertEquals($expected, $actual);
  62. }
  63. public function testLevelEqual()
  64. {
  65. $input = $this->getRecord(Level::Critical);
  66. $expected = clone $input;
  67. $expected['extra'] = [
  68. 'file' => null,
  69. 'line' => null,
  70. 'class' => 'PHPUnit\Framework\TestCase',
  71. 'function' => 'runTest',
  72. 'callType' => '->',
  73. ];
  74. $processor = new IntrospectionProcessor(Level::Critical);
  75. $actual = $processor($input);
  76. $this->assertEquals($expected, $actual);
  77. }
  78. public function testLevelHigher()
  79. {
  80. $input = $this->getRecord(Level::Emergency);
  81. $expected = clone $input;
  82. $expected['extra'] = [
  83. 'file' => null,
  84. 'line' => null,
  85. 'class' => 'PHPUnit\Framework\TestCase',
  86. 'function' => 'runTest',
  87. 'callType' => '->',
  88. ];
  89. $processor = new IntrospectionProcessor(Level::Critical);
  90. $actual = $processor($input);
  91. $this->assertEquals($expected, $actual);
  92. }
  93. }