2
0

FleepHookHandlerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public function tearDown(): void
  34. {
  35. parent::tearDown();
  36. unset($this->handler);
  37. }
  38. /**
  39. * @covers ::__construct
  40. */
  41. public function testConstructorSetsExpectedDefaults()
  42. {
  43. $this->assertEquals(Level::Debug, $this->handler->getLevel());
  44. $this->assertEquals(true, $this->handler->getBubble());
  45. }
  46. /**
  47. * @covers ::getDefaultFormatter
  48. */
  49. public function testHandlerUsesLineFormatterWhichIgnoresEmptyArrays()
  50. {
  51. $record = $this->getRecord(Level::Debug, 'msg');
  52. $expectedFormatter = new LineFormatter(null, null, true, true);
  53. $expected = $expectedFormatter->format($record);
  54. $handlerFormatter = $this->handler->getFormatter();
  55. $actual = $handlerFormatter->format($record);
  56. $this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');
  57. }
  58. /**
  59. * @covers ::__construct
  60. */
  61. public function testConnectionStringisConstructedCorrectly()
  62. {
  63. $this->assertEquals('ssl://fleep.io:443', $this->handler->getConnectionString());
  64. }
  65. }