RequestTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 25
c 2
b 0
f 0
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_send_message() 0 11 1
A test_request_creation() 0 28 1
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