37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once '../vendor/autoload.php';
|
|
|
|
use DJMixHosting\Telegram;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TelegramTest extends TestCase
|
|
{
|
|
private $telegram;
|
|
private $token = 'YOUR_BOT_TOKEN';
|
|
private $chatId = 'YOUR_CHAT_ID';
|
|
|
|
public function testSendMessageReturnsArrayOnSuccess()
|
|
{
|
|
$expectedResult = json_encode(['ok' => true, 'result' => 'Message sent']);
|
|
$this->telegram->method('sendMessage')->willReturn($expectedResult);
|
|
|
|
$result = $this->telegram->send_message('Hello, world!');
|
|
$this->assertIsArray($result);
|
|
$this->assertEquals(['ok' => true, 'result' => 'Message sent'], $result);
|
|
}
|
|
|
|
public function testSendMessageReturnsFalseOnFailure()
|
|
{
|
|
$this->telegram->method('sendMessage')->willReturn(false);
|
|
|
|
$result = $this->telegram->send_message('Hello, world!');
|
|
$this->assertFalse($result);
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->telegram = $this->getMockBuilder(Telegram::class)->setConstructorArgs([$this->token, $this->chatId])->onlyMethods(['sendMessage'])->getMock();
|
|
}
|
|
}
|