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