Passed
Push — master ( 4c2b59...061776 )
by Shahrad
02:09
created

CrashTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 12
c 0
b 0
f 0
dl 0
loc 28
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ test_crash() 0 25 1
A hp$0 ➔ __process() 0 6 1
test_crash() 0 25 ?
A hp$0 ➔ __construct() 0 4 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
16
    public function test_crash(): void
17
    {
18
        $plugin = new class($this) extends Plugin {
19
20
            public function __construct(TestCase $testCase)
21
            {
22
                CrashPad::setAdminChatId(259760855);
23
                $testCase->assertEquals(259760855, CrashPad::getAdminChatId());
24
            }
25
26
            public function __process(Update $update): void
27
            {
28
                CrashPad::report(
29
                    CrashPad::getAdminChatId(),
30
                    new \Exception('test'),
31
                    json_encode($update->getRawData(), JSON_PRETTY_PRINT)
32
                );
33
            }
34
35
        };
36
37
        TelegramTest::loadEnvironment();
38
        (new UpdateHandler())->addPlugins($plugin)->resolve(Telegram::processUpdate(
39
            '{"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!"}}',
40
            $_ENV['TELEGRAM_BOT_TOKEN']
41
        ));
42
    }
43
44
}