FleepHookHandlerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php declare(strict_types=1);
  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\Level;
  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. private FleepHookHandler $handler;
  24. public function setUp(): void
  25. {
  26. parent::setUp();
  27. if (!\extension_loaded('openssl')) {
  28. $this->markTestSkipped('This test requires openssl extension to run');
  29. }
  30. // Create instances of the handler and logger for convenience
  31. $this->handler = new FleepHookHandler(self::TOKEN);
  32. }
  33. /**
  34. * @covers ::__construct
  35. */
  36. public function testConstructorSetsExpectedDefaults()
  37. {
  38. $this->assertEquals(Level::Debug, $this->handler->getLevel());
  39. $this->assertEquals(true, $this->handler->getBubble());
  40. }
  41. /**
  42. * @covers ::getDefaultFormatter
  43. */
  44. public function testHandlerUsesLineFormatterWhichIgnoresEmptyArrays()
  45. {
  46. $record = $this->getRecord(Level::Debug, 'msg');
  47. $expectedFormatter = new LineFormatter(null, null, true, true);
  48. $expected = $expectedFormatter->format($record);
  49. $handlerFormatter = $this->handler->getFormatter();
  50. $actual = $handlerFormatter->format($record);
  51. $this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');
  52. }
  53. /**
  54. * @covers ::__construct
  55. */
  56. public function testConnectionStringisConstructedCorrectly()
  57. {
  58. $this->assertEquals('ssl://fleep.io:443', $this->handler->getConnectionString());
  59. }
  60. }