1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit\Services\Messengers\Clients\Telegram; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Support\Facades\Notification; |
7
|
|
|
use Orchestra\Testbench\TestCase; |
8
|
|
|
use Skater4\LaravelSentryNotifications\Exceptions\UnknownServiceException; |
9
|
|
|
use Skater4\LaravelSentryNotifications\Notifications\Interfaces\NotifableEntityInterface; |
10
|
|
|
use Skater4\LaravelSentryNotifications\Notifications\Services\Telegram\Entities\NotifableTelegramChannel; |
11
|
|
|
use Skater4\LaravelSentryNotifications\Notifications\Services\Telegram\TelegramSentryNotification; |
12
|
|
|
use Skater4\LaravelSentryNotifications\Providers\NotifierServiceProvider; |
13
|
|
|
use Skater4\LaravelSentryNotifications\Providers\TelegramServiceProvider; |
14
|
|
|
use Skater4\LaravelSentryNotifications\Services\Messengers\Clients\Telegram\TelegramClient; |
15
|
|
|
use Illuminate\Container\Container; |
16
|
|
|
use Skater4\LaravelSentryNotifications\Services\Messengers\Interfaces\MessageFormatterInterface; |
17
|
|
|
|
18
|
|
|
class TelegramClientTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param $app |
22
|
|
|
* @return string[] |
23
|
|
|
*/ |
24
|
|
|
protected function getPackageProviders($app): array |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
TelegramServiceProvider::class, |
28
|
|
|
NotifierServiceProvider::class |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
protected function setUp(): void |
36
|
|
|
{ |
37
|
|
|
parent::setUp(); |
38
|
|
|
|
39
|
|
|
Notification::fake(); |
40
|
|
|
$container = Container::getInstance(); |
41
|
|
|
|
42
|
|
|
$formatterMock = $this->createMock(MessageFormatterInterface::class); |
43
|
|
|
$formatterMock->method('getExceptionMessage')->willReturn('Formatted exception message'); |
44
|
|
|
|
45
|
|
|
$notifableEntityMock = $this->createMock(NotifableEntityInterface::class); |
46
|
|
|
|
47
|
|
|
$container->bind(MessageFormatterInterface::class, function () use ($formatterMock) { |
48
|
|
|
return $formatterMock; |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
$container->bind(NotifableEntityInterface::class, function () use ($notifableEntityMock) { |
52
|
|
|
return $notifableEntityMock; |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return void |
58
|
|
|
* @throws UnknownServiceException |
59
|
|
|
*/ |
60
|
|
|
public function testSendMessage() |
61
|
|
|
{ |
62
|
|
|
$client = app(TelegramClient::class); |
63
|
|
|
|
64
|
|
|
Notification::fake(); |
65
|
|
|
Notification::assertNothingSent(); |
66
|
|
|
|
67
|
|
|
$client->sendMessage(new Exception('Test exception'), 'http://example.com/event'); |
68
|
|
|
|
69
|
|
|
Notification::assertSentTo( |
70
|
|
|
new NotifableTelegramChannel(123), |
71
|
|
|
TelegramSentryNotification::class |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.