TelegramBotHandlerTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Logger;
  12. use Monolog\Test\TestCase;
  13. /**
  14. * @author Mazur Alexandr <alexandrmazur96@gmail.com>
  15. * @link https://core.telegram.org/bots/api
  16. */
  17. class TelegramBotHandlerTest extends TestCase
  18. {
  19. /**
  20. * @var TelegramBotHandler
  21. */
  22. private $handler;
  23. public function testSendTelegramRequest(): void
  24. {
  25. $this->createHandler();
  26. $this->handler->handle($this->getRecord());
  27. }
  28. /**
  29. * @param string $apiKey
  30. * @param string $channel
  31. */
  32. private function createHandler(
  33. string $apiKey = 'testKey',
  34. string $channel = 'testChannel',
  35. string $parseMode = 'Markdown',
  36. bool $disableWebPagePreview = false,
  37. bool $disableNotification = true
  38. ): void {
  39. $constructorArgs = [$apiKey, $channel, Logger::DEBUG, true, $parseMode, $disableWebPagePreview, $disableNotification];
  40. $this->handler = $this->getMockBuilder(TelegramBotHandler::class)
  41. ->setConstructorArgs($constructorArgs)
  42. ->onlyMethods(['send'])
  43. ->getMock();
  44. $this->handler->expects($this->atLeast(1))
  45. ->method('send');
  46. }
  47. public function testSetInvalidParseMode(): void
  48. {
  49. $this->expectException(\InvalidArgumentException::class);
  50. $handler = new TelegramBotHandler('testKey', 'testChannel');
  51. $handler->setParseMode('invalid parse mode');
  52. }
  53. public function testSetParseMode(): void
  54. {
  55. $handler = new TelegramBotHandler('testKey', 'testChannel');
  56. $handler->setParseMode('HTML');
  57. }
  58. }