IntrospectionProcessorTest.php 3.0 KB

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