TelegramClientTest::testSendMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 10
eloc 7
cc 1
nc 1
nop 0
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
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    protected function getPackageProviders(/** @scrutinizer ignore-unused */ $app): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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