Passed
Push — master ( 0f659e...1ce9aa )
by Shahrad
02:00
created

HandlerTest.php$0 ➔ __process()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TelegramBotTest;
5
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Dotenv\Dotenv;
8
use TelegramBot\Entities\Update;
9
use TelegramBot\Plugin;
10
use TelegramBot\Request;
11
use TelegramBot\Telegram;
12
use TelegramBot\UpdateHandler;
13
use TelegramBotTest\EchoBot\Handler;
14
15
class HandlerTest extends \PHPUnit\Framework\TestCase
16
{
17
18
    public function test_echo_bot(): void
19
    {
20
        (new Handler())->resolve(Telegram::processUpdate(
21
            '{"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!"}}',
22
            '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
23
        ));
24
25
        $this->assertTrue(true);
26
    }
27
28
    public function test_single_plugin(): void
29
    {
30
        $plugin = new class($this) extends Plugin {
31
32
            public function __construct(private TestCase $class)
33
            {
34
35
            }
36
37
            public function __process(Update $update): void
38
            {
39
                $this->class->assertEquals(1, $update->getUpdateId());
40
            }
41
42
        };
43
44
        (new Dotenv)->load(__DIR__ . '/../.env.example');
45
        (new UpdateHandler())->addPlugins($plugin)->resolve(Telegram::processUpdate(
46
            '{"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!"}}',
47
            $_ENV['TELEGRAM_BOT_TOKEN']
48
        ));
49
    }
50
51
}