RequestTest::test_request_creation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 28
rs 9.6666
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TelegramBotTest;
5
6
use TelegramBot\Request;
7
use TelegramBot\Telegram;
8
9
class RequestTest extends \PHPUnit\Framework\TestCase
10
{
11
12
    public function test_request_creation(): void
13
    {
14
        TelegramTest::loadEnvironment();
15
        Telegram::setToken($_ENV['TELEGRAM_BOT_TOKEN']);
16
17
        $result = Request::create('sendMessage', [
18
            'chat_id' => '259760855',
19
            'text' => 'text',
20
            'parse_mode' => 'Markdown',
21
        ]);
22
23
        $expected = [
24
            'url' => "https://api.telegram.org/bot{$_ENV['TELEGRAM_BOT_TOKEN']}/sendMessage",
25
            'method' => 'GET',
26
            'options' => [
27
                'headers' => [
28
                    'Accept' => 'application/json',
29
                    'User-Agent' => 'TelegramBot-PHP/v1.0.0'
30
                ],
31
                'query' => [
32
                    'chat_id' => '259760855',
33
                    'text' => 'text',
34
                    'parse_mode' => 'Markdown',
35
                ],
36
            ],
37
        ];
38
39
        $this->assertEquals($expected, $result);
40
    }
41
42
    public function test_send_message(): void
43
    {
44
        TelegramTest::loadEnvironment();
45
        Telegram::setToken($_ENV['TELEGRAM_BOT_TOKEN']);
46
47
        $response = Request::sendMessage([
48
            'chat_id' => 259760855,
49
            'text' => 'Hello World',
50
        ]);
51
52
        $this->assertTrue($response->isOk());
53
    }
54
55
}
56