anonymous//tests/HandlerTest.php$0   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TelegramBotTest;
5
6
use PHPUnit\Framework\TestCase;
7
use TelegramBot\Entities\Update;
8
use TelegramBot\Plugin;
9
use TelegramBot\Telegram;
10
use TelegramBot\UpdateHandler;
11
use TelegramBotTest\Examples\EchoBot\Handler;
12
13
class HandlerTest extends \PHPUnit\Framework\TestCase {
14
15
    public function test_echo_bot(): void {
16
        (new Handler())->resolve(Telegram::processUpdate(
17
            '{"update_id":1,"message":{"message_id":1,"from":{"id":1,"is_bot":false,"first_name":"First","last_name":"Last","username":"username","language_code":"en"},"chat":{"id":1,"first_name":"First","last_name":"Last","username":"username","type":"private"},"date":1546300800,"text":"Hello World!"}}',
18
            '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
19
        ));
20
21
        $this->assertTrue(true);
22
    }
23
24
    public function test_single_plugin(): void {
25
        $plugin = new class($this) extends Plugin {
26
27
            public function __construct(private TestCase $class) {
28
29
            }
30
31
            public function __process(Update $update): void {
32
                $this->class->assertEquals(1, $update->getUpdateId());
33
            }
34
35
        };
36
37
        TelegramTest::loadEnvironment();
38
39
        (new UpdateHandler())->addPlugins($plugin)->resolve(Telegram::processUpdate(
40
            '{"update_id":1,"message":{"message_id":1,"from":{"id":1,"is_bot":false,"first_name":"First","last_name":"Last","username":"username","language_code":"en"},"chat":{"id":1,"first_name":"First","last_name":"Last","username":"username","type":"private"},"date":1546300800,"text":"Hello World!"}}',
41
            $_ENV['TELEGRAM_BOT_TOKEN']
42
        ));
43
    }
44
45
}
46