TelegramBotHandlerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. int $topic = 1
  33. ): void {
  34. $constructorArgs = [$apiKey, $channel, Level::Debug, true, $parseMode, $disableWebPagePreview, $disableNotification, $topic];
  35. $this->handler = $this->getMockBuilder(TelegramBotHandler::class)
  36. ->setConstructorArgs($constructorArgs)
  37. ->onlyMethods(['send'])
  38. ->getMock();
  39. $this->handler->expects($this->atLeast(1))
  40. ->method('send');
  41. }
  42. public function testSetInvalidParseMode(): void
  43. {
  44. $this->expectException(\InvalidArgumentException::class);
  45. $handler = new TelegramBotHandler('testKey', 'testChannel');
  46. $handler->setParseMode('invalid parse mode');
  47. }
  48. public function testSetParseMode(): void
  49. {
  50. $handler = new TelegramBotHandler('testKey', 'testChannel');
  51. $handler->setParseMode('HTML');
  52. }
  53. }