TelegramBotHandlerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 tearDown(): void
  22. {
  23. parent::tearDown();
  24. unset($this->handler);
  25. }
  26. public function testSendTelegramRequest(): void
  27. {
  28. $this->createHandler();
  29. $this->handler->handle($this->getRecord());
  30. }
  31. private function createHandler(
  32. string $apiKey = 'testKey',
  33. string $channel = 'testChannel',
  34. string $parseMode = 'Markdown',
  35. bool $disableWebPagePreview = false,
  36. bool $disableNotification = true,
  37. int $topic = 1
  38. ): void {
  39. $constructorArgs = [$apiKey, $channel, Level::Debug, true, $parseMode, $disableWebPagePreview, $disableNotification, $topic];
  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. }