TelegramBotHandlerTest.php 1.8 KB

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