WildfireFormatterTest.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\Formatter;
  11. use Monolog\Logger;
  12. class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @covers Monolog\Formatter\WildfireFormatter::format
  16. */
  17. public function testDefaultFormat()
  18. {
  19. $wildfire = new WildfireFormatter();
  20. $record = array(
  21. 'level' => Logger::ERROR,
  22. 'level_name' => 'ERROR',
  23. 'channel' => 'meh',
  24. 'context' => array('from' => 'logger'),
  25. 'datetime' => new \DateTime("@0"),
  26. 'extra' => array('ip' => '127.0.0.1'),
  27. 'message' => 'log',
  28. );
  29. $message = $wildfire->format($record);
  30. $this->assertEquals(
  31. '125|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},'
  32. .'{"message":"log","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|',
  33. $message
  34. );
  35. }
  36. /**
  37. * @covers Monolog\Formatter\WildfireFormatter::format
  38. */
  39. public function testFormatWithFileAndLine()
  40. {
  41. $wildfire = new WildfireFormatter();
  42. $record = array(
  43. 'level' => Logger::ERROR,
  44. 'level_name' => 'ERROR',
  45. 'channel' => 'meh',
  46. 'context' => array('from' => 'logger'),
  47. 'datetime' => new \DateTime("@0"),
  48. 'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14),
  49. 'message' => 'log',
  50. );
  51. $message = $wildfire->format($record);
  52. $this->assertEquals(
  53. '129|[{"Type":"ERROR","File":"test","Line":14,"Label":"meh"},'
  54. .'{"message":"log","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|',
  55. $message
  56. );
  57. }
  58. /**
  59. * @covers Monolog\Formatter\WildfireFormatter::format
  60. */
  61. public function testFormatWithoutContext()
  62. {
  63. $wildfire = new WildfireFormatter();
  64. $record = array(
  65. 'level' => Logger::ERROR,
  66. 'level_name' => 'ERROR',
  67. 'channel' => 'meh',
  68. 'context' => array(),
  69. 'datetime' => new \DateTime("@0"),
  70. 'extra' => array(),
  71. 'message' => 'log',
  72. );
  73. $message = $wildfire->format($record);
  74. $this->assertEquals(
  75. '58|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},"log"]|',
  76. $message
  77. );
  78. }
  79. /**
  80. * @covers Monolog\Formatter\WildfireFormatter::formatBatch
  81. * @expectedException BadMethodCallException
  82. */
  83. public function testBatchFormatThrowException()
  84. {
  85. $wildfire = new WildfireFormatter();
  86. $record = array(
  87. 'level' => Logger::ERROR,
  88. 'level_name' => 'ERROR',
  89. 'channel' => 'meh',
  90. 'context' => array(),
  91. 'datetime' => new \DateTime("@0"),
  92. 'extra' => array(),
  93. 'message' => 'log',
  94. );
  95. $wildfire->formatBatch(array($record));
  96. }
  97. }