|
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
|
|
|
} |