LineFormatterTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 LineFormatterTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testDefFormatWithString()
  15. {
  16. $formatter = new LineFormatter(null, 'Y-m-d');
  17. $message = $formatter->format(array(
  18. 'level_name' => 'WARNING',
  19. 'channel' => 'log',
  20. 'message' => 'foo',
  21. 'datetime' => new \DateTime,
  22. 'extra' => array(),
  23. ));
  24. $this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo '."\n", $message);
  25. }
  26. public function testDefFormatWithArray()
  27. {
  28. $formatter = new LineFormatter(null, 'Y-m-d');
  29. $message = $formatter->format(array(
  30. 'level_name' => 'ERROR',
  31. 'channel' => 'meh',
  32. 'datetime' => new \DateTime,
  33. 'extra' => array(),
  34. 'message' => array(
  35. 'foo' => 'bar',
  36. 'baz' => 'qux',
  37. )
  38. ));
  39. $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: message(foo: bar, baz: qux) '."\n", $message);
  40. }
  41. public function testDefFormatExtras()
  42. {
  43. $formatter = new LineFormatter(null, 'Y-m-d');
  44. $message = $formatter->format(array(
  45. 'level_name' => 'ERROR',
  46. 'channel' => 'meh',
  47. 'datetime' => new \DateTime,
  48. 'extra' => array('ip' => '127.0.0.1'),
  49. 'message' => 'log',
  50. ));
  51. $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log extra(ip: 127.0.0.1)'."\n", $message);
  52. }
  53. }