testDirectCallOfReportSentryNotificationTriggersNotificationFlow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.9332
eloc 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Feature\Notifications;
4
5
use Illuminate\Support\Facades\Notification;
6
use Mockery;
7
use Orchestra\Testbench\TestCase;
8
use Exception;
9
use Orchestra\Testbench\Exceptions\Handler;
10
use Illuminate\Contracts\Debug\ExceptionHandler;
11
use Skater4\LaravelSentryNotifications\Exceptions\SentryNotifierException;
12
use Skater4\LaravelSentryNotifications\Notifications\Services\Telegram\Entities\NotifableTelegramChannel;
13
use Skater4\LaravelSentryNotifications\Notifications\Services\Telegram\TelegramSentryNotification;
14
use Skater4\LaravelSentryNotifications\Services\SentryNotifier;
15
16
class NotificationFlowTest extends TestCase
17
{
18
    /**
19
     * @return void
20
     */
21
    protected function setUp(): void
22
    {
23
        parent::setUp();
24
        Notification::fake();
25
        $this->app->instance(ExceptionHandler::class, new Handler(app()));
26
    }
27
28
    /**
29
     * @return void
30
     * @throws SentryNotifierException
31
     */
32
    public function testDirectCallOfReportSentryNotificationTriggersNotificationFlow()
33
    {
34
        $sentryNotifierMock = $this->mock(SentryNotifier::class);
35
36
        $sentryNotifierMock->shouldReceive('reportSentryNotification')
37
            ->once()
38
            ->with(Mockery::type(Exception::class))
0 ignored issues
show
Bug introduced by
Exception::class of type string is incompatible with the type TExpectedType expected by parameter $expected of Mockery::type(). ( Ignorable by Annotation )

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

38
            ->with(Mockery::type(/** @scrutinizer ignore-type */ Exception::class))
Loading history...
39
            ->andReturnUsing(function () {
0 ignored issues
show
Bug introduced by
The method andReturnUsing() does not exist on Mockery\ExpectationInterface. Did you maybe mean andReturn()? ( Ignorable by Annotation )

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

39
            ->/** @scrutinizer ignore-call */ andReturnUsing(function () {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
                Notification::send(new NotifableTelegramChannel(123), new TelegramSentryNotification());
41
            });
42
43
        /** @var SentryNotifier $sentryNotifierMock */
44
        $sentryNotifierMock->reportSentryNotification(new Exception('Test exception'));
45
46
        Notification::assertSentTo(
47
            new NotifableTelegramChannel(123),
48
            TelegramSentryNotification::class
49
        );
50
    }
51
}
52