FleepHookHandlerTest.php 2.3 KB

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