CrashTest.php$0 ➔ __process()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TelegramBotTest;
5
6
use PHPUnit\Framework\TestCase;
7
use TelegramBot\CrashPad;
8
use TelegramBot\Entities\Update;
9
use TelegramBot\Plugin;
10
use TelegramBot\Telegram;
11
use TelegramBot\UpdateHandler;
12
13
class CrashTest extends \PHPUnit\Framework\TestCase {
14
15
    public function test_crash(): void {
16
        $plugin = new class($this) extends Plugin {
17
18
            public function __construct(TestCase $testCase) {
19
                Telegram::setAdminId(259760855);
20
                $testCase->assertEquals(259760855, Telegram::getAdminId());
21
            }
22
23
            public function __process(Update $update): void {
24
                CrashPad::sendCrash(
25
                    Telegram::getAdminId(),
26
                    new \Exception('test'),
27
                    json_encode($update->getRawData(), JSON_PRETTY_PRINT)
28
                );
29
                CrashPad::clearCrashLogs();
30
            }
31
32
        };
33
34
        TelegramTest::loadEnvironment();
35
        (new UpdateHandler())->
36
        addPlugins($plugin)->
37
        resolve(Telegram::processUpdate(
38
            '{"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!"}}',
39
            $_ENV['TELEGRAM_BOT_TOKEN']
40
        ));
41
    }
42
43
}
44