TelegramBotHandlerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. {
  40. $constructorArgs = [$apiKey, $channel, Logger::DEBUG, true, $parseMode, $disableWebPagePreview, $disableNotification];
  41. $this->handler = $this->getMockBuilder(TelegramBotHandler::class)
  42. ->setConstructorArgs($constructorArgs)
  43. ->onlyMethods(['send'])
  44. ->getMock();
  45. $this->handler->expects($this->atLeast(1))
  46. ->method('send');
  47. }
  48. public function testSetInvalidParseMode(): void
  49. {
  50. $this->expectException(\InvalidArgumentException::class);
  51. $handler = new TelegramBotHandler('testKey', 'testChannel');
  52. $handler->setParseMode('invalid parse mode');
  53. }
  54. public function testSetParseMode(): void
  55. {
  56. $handler = new TelegramBotHandler('testKey', 'testChannel');
  57. $handler->setParseMode('HTML');
  58. }
  59. }