FleepHookHandlerTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Handler;
  11. use Monolog\Formatter\LineFormatter;
  12. use Monolog\Logger;
  13. use Monolog\Test\TestCase;
  14. /**
  15. * @coversDefaultClass \Monolog\Handler\FleepHookHandler
  16. */
  17. class FleepHookHandlerTest extends TestCase
  18. {
  19. /**
  20. * Default token to use in tests
  21. */
  22. const TOKEN = '123abc';
  23. /**
  24. * @var FleepHookHandler
  25. */
  26. private $handler;
  27. public function setUp()
  28. {
  29. parent::setUp();
  30. if (!extension_loaded('openssl')) {
  31. $this->markTestSkipped('This test requires openssl extension to run');
  32. }
  33. // Create instances of the handler and logger for convenience
  34. $this->handler = new FleepHookHandler(self::TOKEN);
  35. }
  36. /**
  37. * @covers ::__construct
  38. */
  39. public function testConstructorSetsExpectedDefaults()
  40. {
  41. $this->assertEquals(Logger::DEBUG, $this->handler->getLevel());
  42. $this->assertEquals(true, $this->handler->getBubble());
  43. }
  44. /**
  45. * @covers ::getDefaultFormatter
  46. */
  47. public function testHandlerUsesLineFormatterWhichIgnoresEmptyArrays()
  48. {
  49. $record = array(
  50. 'message' => 'msg',
  51. 'context' => array(),
  52. 'level' => Logger::DEBUG,
  53. 'level_name' => Logger::getLevelName(Logger::DEBUG),
  54. 'channel' => 'channel',
  55. 'datetime' => new \DateTime(),
  56. 'extra' => array(),
  57. );
  58. $expectedFormatter = new LineFormatter(null, null, true, true);
  59. $expected = $expectedFormatter->format($record);
  60. $handlerFormatter = $this->handler->getFormatter();
  61. $actual = $handlerFormatter->format($record);
  62. $this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');
  63. }
  64. /**
  65. * @covers ::__construct
  66. */
  67. public function testConnectionStringisConstructedCorrectly()
  68. {
  69. $this->assertEquals('ssl://' . FleepHookHandler::FLEEP_HOST . ':443', $this->handler->getConnectionString());
  70. }
  71. }