ChromePHPFormatterTest.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @covers Monolog\Formatter\ChromePHPFormatter::format
  16. */
  17. public function testDefaultFormat()
  18. {
  19. $formatter = new ChromePHPFormatter();
  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 = $formatter->format($record);
  30. $this->assertEquals(
  31. array(
  32. 'meh',
  33. array(
  34. 'message' => 'log',
  35. 'context' => array('from' => 'logger'),
  36. 'extra' => array('ip' => '127.0.0.1'),
  37. ),
  38. 'unknown',
  39. 'error'
  40. ),
  41. $message
  42. );
  43. }
  44. /**
  45. * @covers Monolog\Formatter\ChromePHPFormatter::format
  46. */
  47. public function testFormatWithFileAndLine()
  48. {
  49. $formatter = new ChromePHPFormatter();
  50. $record = array(
  51. 'level' => Logger::CRITICAL,
  52. 'level_name' => 'CRITICAL',
  53. 'channel' => 'meh',
  54. 'context' => array('from' => 'logger'),
  55. 'datetime' => new \DateTime("@0"),
  56. 'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14),
  57. 'message' => 'log',
  58. );
  59. $message = $formatter->format($record);
  60. $this->assertEquals(
  61. array(
  62. 'meh',
  63. array(
  64. 'message' => 'log',
  65. 'context' => array('from' => 'logger'),
  66. 'extra' => array('ip' => '127.0.0.1'),
  67. ),
  68. 'test : 14',
  69. 'error'
  70. ),
  71. $message
  72. );
  73. }
  74. /**
  75. * @covers Monolog\Formatter\ChromePHPFormatter::format
  76. */
  77. public function testFormatWithoutContext()
  78. {
  79. $formatter = new ChromePHPFormatter();
  80. $record = array(
  81. 'level' => Logger::DEBUG,
  82. 'level_name' => 'DEBUG',
  83. 'channel' => 'meh',
  84. 'context' => array(),
  85. 'datetime' => new \DateTime("@0"),
  86. 'extra' => array(),
  87. 'message' => 'log',
  88. );
  89. $message = $formatter->format($record);
  90. $this->assertEquals(
  91. array(
  92. 'meh',
  93. 'log',
  94. 'unknown',
  95. 'log'
  96. ),
  97. $message
  98. );
  99. }
  100. /**
  101. * @covers Monolog\Formatter\ChromePHPFormatter::formatBatch
  102. */
  103. public function testBatchFormatThrowException()
  104. {
  105. $formatter = new ChromePHPFormatter();
  106. $records = array(
  107. array(
  108. 'level' => Logger::INFO,
  109. 'level_name' => 'INFO',
  110. 'channel' => 'meh',
  111. 'context' => array(),
  112. 'datetime' => new \DateTime("@0"),
  113. 'extra' => array(),
  114. 'message' => 'log',
  115. ),
  116. array(
  117. 'level' => Logger::WARNING,
  118. 'level_name' => 'WARNING',
  119. 'channel' => 'foo',
  120. 'context' => array(),
  121. 'datetime' => new \DateTime("@0"),
  122. 'extra' => array(),
  123. 'message' => 'log2',
  124. ),
  125. );
  126. $this->assertEquals(
  127. array(
  128. array(
  129. 'meh',
  130. 'log',
  131. 'unknown',
  132. 'info'
  133. ),
  134. array(
  135. 'foo',
  136. 'log2',
  137. 'unknown',
  138. 'warn'
  139. ),
  140. ),
  141. $formatter->formatBatch($records)
  142. );
  143. }
  144. }