-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendAudioTest.php
More file actions
94 lines (79 loc) · 3.15 KB
/
SendAudioTest.php
File metadata and controls
94 lines (79 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php namespace Tests\Bot\Methods;
use Tests\TelegramTestCase;
use TelegramPro\Bot\Methods\SendAudio;
use TelegramPro\Bot\Methods\Types\Url;
use TelegramPro\Bot\Methods\Types\Message;
use TelegramPro\Bot\Methods\Types\MethodError;
use TelegramPro\Bot\Methods\Types\MediaCaption;
use TelegramPro\Bot\Methods\FileUploads\FilePath;
use TelegramPro\Bot\Methods\FileUploads\AudioInputFile;
use TelegramPro\Bot\Methods\FileUploads\CanNotOpenFile;
class SendAudioTest extends TelegramTestCase
{
function testSendAudioFileWithFilePath()
{
$response = SendAudio::parameters(
$this->config->cyclingChatId(),
AudioInputFile::fromFilePath(
FilePath::fromString($this->media->mp3())
),
MediaCaption::fromString('[SendAudio] send audio with file path')
)->send($this->telegram);
$this->isOk($response);
self::assertInstanceOf(Message::class, $response->sentMessage());
}
function testSendAudioWithUrl()
{
$response = SendAudio::parameters(
$this->config->cyclingChatId(),
AudioInputFile::fromUrl(
Url::fromString($this->media->audioUrl())
),
MediaCaption::fromString('[SendAudio] send audio with url')
)->send($this->telegram);
$this->isOk($response);
self::assertInstanceOf(Message::class, $response->sentMessage());
}
function testSendAudioWithFileId()
{
$num = rand(0, 32767);
$response = SendAudio::parameters(
$this->config->cyclingChatId(),
AudioInputFile::fromFilePath(
FilePath::fromString($this->media->mp3())
),
MediaCaption::fromString('[SendAudio] send audio with file id 1/2 ' . $num)
)->send($this->telegram);
$audioId = $response->sentMessage()->audio()->fileId();
$response = SendAudio::parameters(
$this->config->cyclingChatId(),
AudioInputFile::fromFileId($audioId),
MediaCaption::fromString('[SendAudio] send audio with file id 2/2 ' . $num)
)->send($this->telegram);
$this->isOk($response);
self::assertInstanceOf(Message::class, $response->sentMessage());
}
function testCanNotSendNonExistentFile()
{
$this->expectException(CanNotOpenFile::class);
SendAudio::parameters(
$this->config->cyclingChatId(),
AudioInputFile::fromFilePath(
FilePath::fromString('non existent file')
),
MediaCaption::fromString('[SendAudio] parse error test')
)->send($this->telegram);
}
function testCanParseError()
{
$response = SendAudio::parameters(
$this->config->cyclingChatId(),
AudioInputFile::fromUrl(Url::fromString('https://bob')),
MediaCaption::fromString('[SendAudio] parse error test')
)->send($this->telegram);
self::assertFalse($response->ok());
self::assertInstanceOf(MethodError::class, $response->error());
self::assertSame('400', $response->error()->code());
self::assertNotEmpty($response->error()->description());
}
}