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 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\TestCase;
  24. use Monolog\Handler\TestHandler;
  25. class IntrospectionProcessorTest extends TestCase
  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. }