|
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\Application\Inbox\Notification; |
|
16
|
|
|
|
|
17
|
|
|
use Kreta\Notifier\Application\Inbox\Notification\PublishNotificationCommand; |
|
18
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\Notification; |
|
19
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationAlreadyExists; |
|
20
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationDoesNotExist; |
|
21
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationId; |
|
22
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationRepository; |
|
23
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\User; |
|
24
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserDoesNotExist; |
|
25
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
26
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserRepository; |
|
27
|
|
|
use PhpSpec\ObjectBehavior; |
|
28
|
|
|
use Prophecy\Argument; |
|
29
|
|
|
|
|
30
|
|
|
class PublishNotificationSpec extends ObjectBehavior |
|
31
|
|
|
{ |
|
32
|
|
|
private $notificationId; |
|
33
|
|
|
private $userId; |
|
34
|
|
|
|
|
35
|
|
|
function let( |
|
36
|
|
|
NotificationRepository $repository, |
|
37
|
|
|
UserRepository $userRepository, |
|
38
|
|
|
PublishNotificationCommand $command |
|
39
|
|
|
) { |
|
40
|
|
|
$this->beConstructedWith($repository, $userRepository); |
|
41
|
|
|
|
|
42
|
|
|
$command->notificationId()->shouldBeCalled()->willReturn('notification-id'); |
|
43
|
|
|
$command->userId()->shouldBeCalled()->willReturn('user-id'); |
|
44
|
|
|
$command->body()->shouldBeCalled()->willReturn('The notification body'); |
|
45
|
|
|
|
|
46
|
|
|
$this->notificationId = NotificationId::generate('notification-id'); |
|
47
|
|
|
$this->userId = UserId::generate('user-id'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function it_does_not_publish_notification_when_the_notification_already_exists( |
|
51
|
|
|
PublishNotificationCommand $command, |
|
52
|
|
|
NotificationRepository $repository, |
|
53
|
|
|
Notification $notification, |
|
54
|
|
|
NotificationId $notificationId |
|
55
|
|
|
) { |
|
56
|
|
|
$repository->get($this->notificationId)->shouldBeCalled()->willReturn($notification); |
|
57
|
|
|
$notification->id()->shouldBeCalled()->willReturn($notificationId); |
|
58
|
|
|
$this->shouldThrow(NotificationAlreadyExists::class)->during__invoke($command); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function it_does_not_publish_notification_when_the_user_does_not_exist( |
|
62
|
|
|
PublishNotificationCommand $command, |
|
63
|
|
|
NotificationRepository $repository, |
|
64
|
|
|
UserRepository $userRepository |
|
65
|
|
|
) { |
|
66
|
|
|
$repository->get($this->notificationId)->shouldBeCalled()->willThrow(NotificationDoesNotExist::class); |
|
67
|
|
|
$userRepository->get($this->userId)->shouldBeCalled()->willThrow(UserDoesNotExist::class); |
|
68
|
|
|
$this->shouldThrow(UserDoesNotExist::class)->during__invoke($command); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function it_publishes_notification( |
|
72
|
|
|
PublishNotificationCommand $command, |
|
73
|
|
|
NotificationRepository $repository, |
|
74
|
|
|
UserRepository $userRepository, |
|
75
|
|
|
User $user |
|
76
|
|
|
) { |
|
77
|
|
|
$repository->get($this->notificationId)->shouldBeCalled()->willThrow(NotificationDoesNotExist::class); |
|
78
|
|
|
$userRepository->get($this->userId)->shouldBeCalled()->willReturn($user); |
|
79
|
|
|
$repository->save(Argument::type(Notification::class))->shouldBeCalled(); |
|
80
|
|
|
$this->__invoke($command); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|