Passed
Push — master ( 72ea7a...b665cb )
by Shahrad
12:25
created

WebhookTest::test_nothing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TelegramBotTest;
4
5
use PHPUnit\Framework\TestCase;
6
use TelegramBot\Entities\Message;
7
use TelegramBot\Entities\Update;
8
use TelegramBot\Plugin;
9
use TelegramBot\UpdateHandler;
10
11
class WebhookTest extends \PHPUnit\Framework\TestCase {
12
13
   public function testAnonymousPlugins() {
14
      $plugin = new class($this) extends Plugin {
15
16
         private $testCase;
17
18
         public function __construct(TestCase $testCase) {
19
            $this->testCase = $testCase;
20
         }
21
22
         public function onMessage(int $update_id, Message $message): \Generator {
23
            $this->testCase->assertEquals(1, $update_id);
24
            $this->testCase->assertEquals('Hello World!', $message->getText());
25
            yield;
26
         }
27
28
      };
29
30
      $message = DummyUpdate::message();
31
      $message->set('text', 'Hello World!');
32
33
      (new UpdateHandler())->addPlugins($plugin)->resolve(new Update([
34
         'update_id' => 1,
35
         'message' => $message->getRawData(),
36
      ]));
37
   }
38
39
   public function testFilterIncomingUpdates() {
40
41
      $plugin = new class($this) extends Plugin {
42
43
         public function __construct(TestCase $testCase) {
44
            $this->testCase = $testCase;
0 ignored issues
show
Bug Best Practice introduced by
The property testCase does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
         }
46
47
         public function __process(Update $update): void {
48
            $this->testCase->fail('This should not be called');
49
         }
50
      };
51
52
      $handler = (new UpdateHandler())->addPlugins($plugin);
53
54
      $handler->filterIncomingUpdates([
55
         Update::TYPE_MESSAGE
56
      ]);
57
58
      $handler->resolve(new Update([
59
         'update_id' => 1,
60
         'message' => DummyUpdate::message()->getRawData(),
61
      ]));
62
63
      $this->assertTrue(true);
64
   }
65
66
}