LogglyFormatterTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Test\TestCase;
  12. class LogglyFormatterTest extends TestCase
  13. {
  14. /**
  15. * @covers Monolog\Formatter\LogglyFormatter::__construct
  16. */
  17. public function testConstruct()
  18. {
  19. $formatter = new LogglyFormatter();
  20. $this->assertEquals(LogglyFormatter::BATCH_MODE_NEWLINES, $formatter->getBatchMode());
  21. $formatter = new LogglyFormatter(LogglyFormatter::BATCH_MODE_JSON);
  22. $this->assertEquals(LogglyFormatter::BATCH_MODE_JSON, $formatter->getBatchMode());
  23. }
  24. /**
  25. * @covers Monolog\Formatter\LogglyFormatter::format
  26. */
  27. public function testFormat()
  28. {
  29. $formatter = new LogglyFormatter();
  30. $record = $this->getRecord();
  31. $formatted_decoded = json_decode($formatter->format($record), true);
  32. $this->assertArrayNotHasKey("datetime", $formatted_decoded);
  33. $this->assertArrayHasKey("timestamp", $formatted_decoded);
  34. $this->assertEquals(new \DateTime($formatted_decoded["timestamp"]), $record["datetime"]);
  35. }
  36. }