BaseClientTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
dl 0
loc 78
rs 10
eloc 22

12 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ publicGetMessageFormatter() 0 3 1
testMessageFormatterIsReturnedCorrectly() 0 21 ?
A hp$0 ➔ __construct() 0 3 1
testNotifableEntityIsReturnedCorrectly() 0 21 ?
A hp$0 ➔ testMessageFormatterIsReturnedCorrectly() 0 21 1
A hp$2 ➔ publicGetNotification() 0 3 1
A hp$1 ➔ testNotifableEntityIsReturnedCorrectly() 0 21 1
testNotificationIsReturnedCorrectly() 0 21 ?
A hp$1 ➔ __construct() 0 3 1
A hp$1 ➔ publicGetNotifableEntity() 0 3 1
A hp$2 ➔ __construct() 0 3 1
A hp$2 ➔ testNotificationIsReturnedCorrectly() 0 21 1
1
<?php
2
3
namespace Tests\Unit\Services\Messengers\Clients\Base;
4
5
use Illuminate\Notifications\Notification;
6
use PHPUnit\Framework\TestCase;
7
use Skater4\LaravelSentryNotifications\Notifications\Factories\NotificationEntityFactory;
8
use Skater4\LaravelSentryNotifications\Notifications\Factories\NotificationFactory;
9
use Skater4\LaravelSentryNotifications\Notifications\Interfaces\NotifableEntityInterface;
10
use Skater4\LaravelSentryNotifications\Services\Messengers\Clients\Base\BaseClient;
11
use Skater4\LaravelSentryNotifications\Services\Messengers\Factories\MessageFormatterFactory;
12
use Skater4\LaravelSentryNotifications\Services\Messengers\Interfaces\MessageFormatterInterface;
13
14
class BaseClientTest extends TestCase
15
{
16
    /**
17
     * @return void
18
     */
19
    public function testMessageFormatterIsReturnedCorrectly()
20
    {
21
        $formatterFactoryMock = $this->createMock(MessageFormatterFactory::class);
22
23
        $formatterMock = $this->createMock(MessageFormatterInterface::class);
24
25
        $formatterFactoryMock->method('create')->willReturn($formatterMock);
26
27
        $client = new class($formatterFactoryMock) extends BaseClient {
28
            public function __construct($messageFormatterFactory)
29
            {
30
                $this->messageFormatter = $messageFormatterFactory->create();
31
            }
32
33
            public function publicGetMessageFormatter(): MessageFormatterInterface
34
            {
35
                return $this->getMessageFormatter();
36
            }
37
        };
38
39
        $this->assertInstanceOf(MessageFormatterInterface::class, $client->publicGetMessageFormatter());
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    public function testNotifableEntityIsReturnedCorrectly()
46
    {
47
        $notifableEntityFactoryMock = $this->createMock(NotificationEntityFactory::class);
48
49
        $notifableEntityMock = $this->createMock(NotifableEntityInterface::class);
50
51
        $notifableEntityFactoryMock->method('create')->willReturn($notifableEntityMock);
52
53
        $client = new class($notifableEntityFactoryMock) extends BaseClient {
54
            public function __construct($notifableEntityFactory)
55
            {
56
                $this->notifableEntity = $notifableEntityFactory->create();
57
            }
58
59
            public function publicGetNotifableEntity(): NotifableEntityInterface
60
            {
61
                return $this->getNotifableEntity();
62
            }
63
        };
64
65
        $this->assertInstanceOf(NotifableEntityInterface::class, $client->publicGetNotifableEntity());
66
    }
67
68
    /**
69
     * @return void
70
     */
71
    public function testNotificationIsReturnedCorrectly()
72
    {
73
        $notificationFactoryMock = $this->createMock(NotificationFactory::class);
74
75
        $notificationMock = $this->createMock(Notification::class);
76
77
        $notificationFactoryMock->method('create')->willReturn($notificationMock);
78
79
        $client = new class($notificationFactoryMock) extends BaseClient {
80
            public function __construct($notificationFactory)
81
            {
82
                $this->notificationClass = $notificationFactory->create();
83
            }
84
85
            public function publicGetNotification(): Notification
86
            {
87
                return $this->getNotificationClass();
88
            }
89
        };
90
91
        $this->assertInstanceOf(Notification::class, $client->publicGetNotification());
92
    }
93
}
94