Completed
Push — master ( 7fe5eb...9bad48 )
by Beñat
08:54 queued 04:27
created

NotificationPublishedEventHandlerSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 8
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
B it_can_be_handle() 0 27 1
A it_subscribes_to() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Spec\Kreta\Notifier\Domain\ReadEvent\Inbox\Notification;
16
17
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationBody;
18
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationId;
19
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationPublished;
20
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationStatus;
21
use Kreta\Notifier\Domain\Model\Inbox\UserId;
22
use Kreta\Notifier\Domain\ReadEvent\Inbox\Notification\NotificationPublishedEventHandler;
23
use Kreta\Notifier\Domain\ReadModel\Inbox\Notification\Notification;
24
use Kreta\Notifier\Domain\ReadModel\Inbox\Notification\NotificationView;
25
use Kreta\SharedKernel\Domain\ReadEvent\EventHandler;
26
use PhpSpec\ObjectBehavior;
27
use Prophecy\Argument;
28
29
class NotificationPublishedEventHandlerSpec extends ObjectBehavior
30
{
31
    function let(NotificationView $view)
32
    {
33
        $this->beConstructedWith($view);
34
    }
35
36
    function it_can_be_handle(
37
        NotificationPublished $event,
38
        NotificationView $view,
39
        NotificationId $notificationId,
40
        UserId $userId,
41
        NotificationBody $body,
42
        NotificationStatus $status,
43
        \DateTimeImmutable $occurredOn
44
    ) {
45
        $this->shouldHaveType(NotificationPublishedEventHandler::class);
46
        $this->shouldImplement(EventHandler::class);
47
48
        $event->notificationId()->shouldBeCalled()->willReturn($notificationId);
49
        $notificationId->id()->shouldBeCalled()->willReturn('notification-id');
50
        $event->userId()->shouldBeCalled()->willReturn($userId);
51
        $userId->id()->shouldBeCalled()->willReturn('user-id');
52
        $event->body()->shouldBeCalled()->willReturn($body);
53
        $body->body()->shouldBeCalled()->willReturn('The notification body');
54
        $event->status()->shouldBeCalled()->willReturn($status);
55
        $status->status()->shouldBeCalled()->willReturn('unread');
56
        $event->occurredOn()->shouldBeCalled()->willReturn($occurredOn);
57
        $occurredOn->getTimestamp()->shouldBeCalled()->willReturn(2313312);
58
59
        $view->save(Argument::type(Notification::class))->shouldBeCalled();
60
61
        $this->handle($event);
62
    }
63
64
    function it_subscribes_to()
65
    {
66
        $this->isSubscribeTo()->shouldReturn(NotificationPublished::class);
67
    }
68
}
69