dj_mix_hosting_software/tests/TelegramTest.php
Cody Cook 74f1d6e193
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 53s
PHPUnit stuff.
2024-05-14 17:54:06 -07:00

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();
}
}