WildfireFormatterTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\Formatter;
  11. use Monolog\Level;
  12. class WildfireFormatterTest extends \Monolog\Test\MonologTestCase
  13. {
  14. /**
  15. * @covers Monolog\Formatter\WildfireFormatter::format
  16. */
  17. public function testDefaultFormat()
  18. {
  19. $wildfire = new WildfireFormatter();
  20. $record = $this->getRecord(
  21. Level::Error,
  22. 'log',
  23. channel: 'meh',
  24. context: ['from' => 'logger'],
  25. extra: ['ip' => '127.0.0.1'],
  26. );
  27. $message = $wildfire->format($record);
  28. $this->assertEquals(
  29. '125|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},'
  30. .'{"message":"log","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|',
  31. $message
  32. );
  33. }
  34. /**
  35. * @covers Monolog\Formatter\WildfireFormatter::format
  36. */
  37. public function testFormatWithFileAndLine()
  38. {
  39. $wildfire = new WildfireFormatter();
  40. $record = $this->getRecord(
  41. Level::Error,
  42. 'log',
  43. channel: 'meh',
  44. context: ['from' => 'logger'],
  45. extra: ['ip' => '127.0.0.1', 'file' => 'test', 'line' => 14],
  46. );
  47. $message = $wildfire->format($record);
  48. $this->assertEquals(
  49. '129|[{"Type":"ERROR","File":"test","Line":14,"Label":"meh"},'
  50. .'{"message":"log","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|',
  51. $message
  52. );
  53. }
  54. /**
  55. * @covers Monolog\Formatter\WildfireFormatter::format
  56. */
  57. public function testFormatWithoutContext()
  58. {
  59. $wildfire = new WildfireFormatter();
  60. $record = $this->getRecord(
  61. Level::Error,
  62. 'log',
  63. channel: 'meh',
  64. );
  65. $message = $wildfire->format($record);
  66. $this->assertEquals(
  67. '58|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},"log"]|',
  68. $message
  69. );
  70. }
  71. /**
  72. * @covers Monolog\Formatter\WildfireFormatter::formatBatch
  73. */
  74. public function testBatchFormatThrowException()
  75. {
  76. $this->expectException(\BadMethodCallException::class);
  77. $wildfire = new WildfireFormatter();
  78. $record = $this->getRecord(
  79. Level::Error,
  80. 'log',
  81. channel: 'meh',
  82. );
  83. $wildfire->formatBatch([$record]);
  84. }
  85. /**
  86. * @covers Monolog\Formatter\WildfireFormatter::format
  87. */
  88. public function testTableFormat()
  89. {
  90. $wildfire = new WildfireFormatter();
  91. $record = $this->getRecord(
  92. Level::Error,
  93. 'table-message',
  94. channel: 'table-channel',
  95. context: [
  96. 'table' => [
  97. ['col1', 'col2', 'col3'],
  98. ['val1', 'val2', 'val3'],
  99. ['foo1', 'foo2', 'foo3'],
  100. ['bar1', 'bar2', 'bar3'],
  101. ],
  102. ],
  103. );
  104. $message = $wildfire->format($record);
  105. $this->assertEquals(
  106. '171|[{"Type":"TABLE","File":"","Line":"","Label":"table-channel: table-message"},[["col1","col2","col3"],["val1","val2","val3"],["foo1","foo2","foo3"],["bar1","bar2","bar3"]]]|',
  107. $message
  108. );
  109. }
  110. }