IntrospectionProcessorTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Processor;
  11. use Monolog\TestCase;
  12. use Monolog\Handler\TestHandler;
  13. class IntrospectionProcessorTest extends TestCase
  14. {
  15. public function getHandler()
  16. {
  17. $processor = new IntrospectionProcessor();
  18. $handler = new TestHandler();
  19. $handler->pushProcessor($processor);
  20. return $handler;
  21. }
  22. public function testProcessorFromClass()
  23. {
  24. $handler = $this->getHandler();
  25. $tester = new \Acme\Tester;
  26. $tester->test($handler, $this->getRecord());
  27. list($record) = $handler->getRecords();
  28. $this->assertEquals(__FILE__, $record['extra']['file']);
  29. $this->assertEquals(58, $record['extra']['line']);
  30. $this->assertEquals('Acme\Tester', $record['extra']['class']);
  31. $this->assertEquals('test', $record['extra']['function']);
  32. }
  33. public function testProcessorFromFunc()
  34. {
  35. $handler = $this->getHandler();
  36. \Acme\tester($handler, $this->getRecord());
  37. list($record) = $handler->getRecords();
  38. $this->assertEquals(__FILE__, $record['extra']['file']);
  39. $this->assertEquals(64, $record['extra']['line']);
  40. $this->assertEquals(null, $record['extra']['class']);
  41. $this->assertEquals('Acme\tester', $record['extra']['function']);
  42. }
  43. }
  44. namespace Acme;
  45. class Tester
  46. {
  47. public function test($handler, $record)
  48. {
  49. $handler->handle($record);
  50. }
  51. }
  52. function tester($handler, $record)
  53. {
  54. $handler->handle($record);
  55. }