Add SendVenue method to send venue information
This commit is contained in:
parent
e4787b90a1
commit
012fc4fe0f
3 changed files with 200 additions and 0 deletions
102
tests/TgBotLib/Methods/SendVenueTest.php
Normal file
102
tests/TgBotLib/Methods/SendVenueTest.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Methods;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Exceptions\TelegramException;
|
||||
use TgBotLib\Objects\Message;
|
||||
|
||||
class SendVenueTest extends TestCase
|
||||
{
|
||||
private static Bot $bot;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$bot = new Bot(BOT_TOKEN);
|
||||
self::$bot->setAutoRetry(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the basic `sendVenue` functionality
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendVenue(): void
|
||||
{
|
||||
$result = self::$bot->sendVenue(
|
||||
chat_id: TEST_CHAT_ID,
|
||||
latitude: 51.5074,
|
||||
longitude: -0.1278,
|
||||
title: 'Big Ben',
|
||||
address: 'Westminster, London SW1A 0AA'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Message::class, $result);
|
||||
$this->assertNotNull($result->getVenue());
|
||||
$this->assertEquals('Big Ben', $result->getVenue()->getTitle());
|
||||
$this->assertEquals('Westminster, London SW1A 0AA', $result->getVenue()->getAddress());
|
||||
$this->assertEquals(51.507394, $result->getVenue()->getLocation()->getLatitude());
|
||||
$this->assertEquals(-0.127813, $result->getVenue()->getLocation()->getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sending venue with additional parameters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendVenueWithAdditionalParams(): void
|
||||
{
|
||||
$result = self::$bot->sendVenue(
|
||||
chat_id: TEST_CHAT_ID,
|
||||
latitude: 51.5074,
|
||||
longitude: -0.1278,
|
||||
title: 'Big Ben',
|
||||
address: 'Westminster, London SW1A 0AA',
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Message::class, $result);
|
||||
$this->assertNotNull($result->getVenue());
|
||||
$this->assertEquals('Big Ben', $result->getVenue()->getTitle());
|
||||
$this->assertEquals('Westminster, London SW1A 0AA', $result->getVenue()->getAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sending venue with invalid latitude
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendVenueInvalidLatitude(): void
|
||||
{
|
||||
$this->expectException(TelegramException::class);
|
||||
|
||||
self::$bot->sendVenue(
|
||||
chat_id: TEST_CHAT_ID,
|
||||
latitude: 'invalid',
|
||||
longitude: -0.1278,
|
||||
title: 'Big Ben',
|
||||
address: 'Westminster, London SW1A 0AA'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sending venue with empty address
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendVenueEmptyAddress(): void
|
||||
{
|
||||
$this->expectException(TelegramException::class);
|
||||
|
||||
self::$bot->sendVenue(
|
||||
chat_id: TEST_CHAT_ID,
|
||||
latitude: 51.5074,
|
||||
longitude: -0.1278,
|
||||
title: 'Big Ben',
|
||||
address: ''
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue