Add SendPoll method with tests and enhance Poll object
This commit is contained in:
parent
33f7a094fc
commit
9a4e537294
6 changed files with 234 additions and 11 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Exceptions\TelegramException;
|
||||
use TgBotLib\Objects\Message;
|
||||
|
||||
class SendContactTest extends TestCase
|
||||
|
|
74
tests/TgBotLib/Methods/SendPollTest.php
Normal file
74
tests/TgBotLib/Methods/SendPollTest.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Methods;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Objects\InputPollOption;
|
||||
use TgBotLib\Objects\Message;
|
||||
|
||||
class SendPollTest extends TestCase
|
||||
{
|
||||
private static Bot $bot;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// Initialize the Bot instance before tests
|
||||
self::$bot = new Bot(BOT_TOKEN);
|
||||
self::$bot->setAutoRetry(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the sendPoll method with basic parameters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendPollBasic(): void
|
||||
{
|
||||
|
||||
// Execute the method and retrieve the result
|
||||
$result = self::$bot->sendPoll(
|
||||
chat_id: TEST_CHAT_ID,
|
||||
question: 'What is your favorite color?',
|
||||
options: [
|
||||
(new InputPollOption())->setText('Red'),
|
||||
(new InputPollOption())->setText('Blue'),
|
||||
(new InputPollOption())->setText('Green'),
|
||||
]
|
||||
);
|
||||
|
||||
// Assert that the result is an instance of Message
|
||||
$this->assertInstanceOf(Message::class, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the sendPoll method with advanced options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendPollWithAdvancedOptions(): void
|
||||
{
|
||||
// Execute the method and retrieve the result
|
||||
$result = self::$bot->sendPoll(
|
||||
chat_id: TEST_CHAT_ID,
|
||||
question: 'What is your favorite color?',
|
||||
options: [
|
||||
(new InputPollOption())->setText('Red'),
|
||||
(new InputPollOption())->setText('Blue'),
|
||||
(new InputPollOption())->setText('Green'),
|
||||
],
|
||||
is_anonymous: false,
|
||||
allows_multiple_answers: true,
|
||||
correct_option_id: 1,
|
||||
explanation: 'The correct answer is Blue.',
|
||||
explanation_parse_mode: 'MarkdownV2',
|
||||
open_period: 60,
|
||||
close_date: strtotime('+1 day')
|
||||
);
|
||||
|
||||
// Assert that the result is an instance of Message
|
||||
$this->assertInstanceOf(Message::class, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue