|
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
|
|
|
|