Skip to content

Commit 55dd714

Browse files
committed
Add unit test for Request
1 parent 466752d commit 55dd714

1 file changed

Lines changed: 243 additions & 0 deletions

File tree

tests/Unit/RequestTest.php

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Longman\TelegramBot\Telegram;
6+
use Longman\TelegramBot\Request;
7+
8+
class RequestTest extends TestCase
9+
{
10+
/**
11+
* @var \Longman\TelegramBot\Telegram
12+
*/
13+
private $telegram;
14+
15+
/**
16+
* @var array
17+
*/
18+
private $data = [
19+
'user_id' => 123,
20+
'chat_id' => 123,
21+
'text' => 'text'
22+
];
23+
24+
/**
25+
* setUp
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->telegram = new Telegram('apikey', 'testbot');
30+
}
31+
32+
public function testSendMethod()
33+
{
34+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
35+
Request::send('non_existing_method');
36+
}
37+
38+
public function testSendMessageMethods()
39+
{
40+
Request::getMe();
41+
42+
Request::sendMessage($this->data);
43+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
44+
Request::sendMessage([]);
45+
}
46+
47+
public function testForwardMethod()
48+
{
49+
Request::forwardMessage($this->data);
50+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
51+
Request::forwardMessage([]); #throw new TelegramException('Data is empty!');
52+
}
53+
54+
public function testSendPhotoMethod()
55+
{
56+
Request::sendPhoto($this->data);
57+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
58+
Request::sendPhoto([]);
59+
}
60+
61+
public function testSendAudioMethod()
62+
{
63+
Request::sendAudio($this->data);
64+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
65+
Request::sendAudio([]);
66+
}
67+
68+
public function testSendDocumentMethod()
69+
{
70+
Request::sendDocument($this->data);
71+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
72+
Request::sendDocument([]);
73+
}
74+
75+
public function testSendStickerMethod()
76+
{
77+
Request::sendSticker($this->data);
78+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
79+
Request::sendSticker([]);
80+
}
81+
82+
public function testSendVideoMethod()
83+
{
84+
Request::sendVideo($this->data);
85+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
86+
Request::sendVideo([]);
87+
}
88+
89+
public function testSendVoiceMethod()
90+
{
91+
Request::sendVoice($this->data);
92+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
93+
Request::sendVoice([]);
94+
}
95+
96+
public function testSendLocationMethod()
97+
{
98+
Request::sendLocation($this->data);
99+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
100+
Request::sendLocation([]);
101+
}
102+
103+
public function testSendVenueMethod()
104+
{
105+
Request::sendVenue($this->data);
106+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
107+
Request::sendVenue([]);
108+
}
109+
110+
public function testSendContactMethod()
111+
{
112+
Request::sendContact($this->data);
113+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
114+
Request::sendContact([]);
115+
}
116+
117+
public function testSendChatActionMethod()
118+
{
119+
Request::sendChatAction($this->data);
120+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
121+
Request::sendChatAction([]);
122+
}
123+
124+
public function testGetUserProfilePhotosMethod()
125+
{
126+
Request::getUserProfilePhotos($this->data);
127+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
128+
Request::getUserProfilePhotos([]);
129+
130+
// Putting together
131+
Request::getUpdates($this->data);
132+
Request::setWebhook('http://www.myserver.com');
133+
//TODO $max_connections = null
134+
}
135+
136+
public function testGetFileMethod()
137+
{
138+
Request::getFile($this->data);
139+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
140+
Request::getFile([]);
141+
}
142+
143+
public function testKickChatMemberMethod()
144+
{
145+
Request::kickChatMember($this->data);
146+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
147+
Request::kickChatMember([]);
148+
}
149+
150+
public function testLeaveChatMethod()
151+
{
152+
Request::leaveChat($this->data);
153+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
154+
Request::leaveChat([]);
155+
}
156+
157+
public function testUnbanChatMemberMethod()
158+
{
159+
Request::unbanChatMember($this->data);
160+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
161+
Request::unbanChatMember([]);
162+
}
163+
164+
public function testGetChatMethod()
165+
{
166+
Request::getChat($this->data);
167+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
168+
Request::getChat([]);
169+
}
170+
171+
public function testGetChatAdministratorMethod()
172+
{
173+
Request::getChatAdministrators($this->data);
174+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
175+
Request::getChatAdministrators([]);
176+
}
177+
178+
public function testGetChatMembersCountMethod()
179+
{
180+
Request::getChatMembersCount($this->data);
181+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
182+
Request::getChatMembersCount([]);
183+
}
184+
185+
public function testGetChatMembersMethod()
186+
{
187+
Request::getChatMember($this->data);
188+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
189+
Request::getChatMember([]);
190+
}
191+
192+
public function testCallbackQueryMethod()
193+
{
194+
Request::answerCallbackQuery($this->data);
195+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
196+
Request::answerCallbackQuery([]);
197+
}
198+
199+
public function testAnswerInlineQueryMethod()
200+
{
201+
Request::answerInlineQuery($this->data);
202+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
203+
Request::answerInlineQuery([]);
204+
}
205+
206+
public function testEditMessageTextMethod()
207+
{
208+
Request::editMessageText($this->data);
209+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
210+
Request::editMessageText([]);
211+
}
212+
213+
public function testEditMessageCaptionMethod()
214+
{
215+
Request::editMessageCaption($this->data);
216+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
217+
Request::editMessageCaption([]);
218+
}
219+
220+
public function testEditMessageReplyMarkupMethod()
221+
{
222+
Request::editMessageReplyMarkup($this->data);
223+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
224+
Request::editMessageReplyMarkup([]);
225+
226+
// Putting together
227+
Request::getMyCommands();
228+
}
229+
230+
public function testSetMyCommandsMethod()
231+
{
232+
Request::setMyCommands($this->data);
233+
$this->expectException(\Longman\TelegramBot\Exception\TelegramException::class);
234+
Request::setMyCommands([]);
235+
}
236+
237+
public function testEmptyResponseMethod()
238+
{
239+
$server_response = Request::emptyResponse();
240+
$this->assertEquals(true, $server_response->isOk());
241+
$this->assertEquals(true, $server_response->getResult());
242+
}
243+
}

0 commit comments

Comments
 (0)