WildfireFormatterTest.php 3.4 KB

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