PHPUnit stuff.
This commit is contained in:
parent
91dc776e4d
commit
74f1d6e193
30 changed files with 358 additions and 89 deletions
36
tests/TelegramTest.php
Normal file
36
tests/TelegramTest.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue