|
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\MarkAsReadNotificationCommand; |
|
18
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\Notification; |
|
19
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationDoesNotExist; |
|
20
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationId; |
|
21
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationRepository; |
|
22
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\User; |
|
23
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserDoesNotExist; |
|
24
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
25
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserRepository; |
|
26
|
|
|
use PhpSpec\ObjectBehavior; |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
class MarkAsReadNotificationSpec extends ObjectBehavior |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
private $notificationId; |
|
31
|
|
|
private $userId; |
|
32
|
|
|
|
|
33
|
|
|
function let( |
|
34
|
|
|
NotificationRepository $repository, |
|
35
|
|
|
UserRepository $userRepository, |
|
36
|
|
|
MarkAsReadNotificationCommand $command |
|
37
|
|
|
) { |
|
38
|
|
|
$this->beConstructedWith($repository, $userRepository); |
|
39
|
|
|
|
|
40
|
|
|
$command->notificationId()->shouldBeCalled()->willReturn('notification-id'); |
|
41
|
|
|
$command->userId()->shouldBeCalled()->willReturn('user-id'); |
|
42
|
|
|
|
|
43
|
|
|
$this->notificationId = NotificationId::generate('notification-id'); |
|
44
|
|
|
$this->userId = UserId::generate('user-id'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function it_does_not_mark_as_read_notification_when_the_user_does_not_exist( |
|
48
|
|
|
MarkAsReadNotificationCommand $command, |
|
49
|
|
|
UserRepository $userRepository |
|
50
|
|
|
) { |
|
51
|
|
|
$userRepository->get($this->userId)->shouldBeCalled()->willThrow(UserDoesNotExist::class); |
|
52
|
|
|
$this->shouldThrow(UserDoesNotExist::class)->during__invoke($command); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function it_does_not_mark_as_read_notification_when_the_notification_does_not_exist( |
|
56
|
|
|
MarkAsReadNotificationCommand $command, |
|
57
|
|
|
NotificationRepository $repository, |
|
58
|
|
|
UserRepository $userRepository, |
|
59
|
|
|
User $user |
|
60
|
|
|
) { |
|
61
|
|
|
$userRepository->get($this->userId)->shouldBeCalled()->willReturn($user); |
|
62
|
|
|
$repository->get($this->notificationId)->shouldBeCalled()->willThrow(NotificationDoesNotExist::class); |
|
63
|
|
|
$this->shouldThrow(NotificationDoesNotExist::class)->during__invoke($command); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function it_marks_as_read_notification( |
|
67
|
|
|
MarkAsReadNotificationCommand $command, |
|
68
|
|
|
Notification $notification, |
|
69
|
|
|
NotificationRepository $repository, |
|
70
|
|
|
UserRepository $userRepository, |
|
71
|
|
|
User $user |
|
72
|
|
|
) { |
|
73
|
|
|
$userRepository->get($this->userId)->shouldBeCalled()->willReturn($user); |
|
74
|
|
|
$repository->get($this->notificationId)->shouldBeCalled()->willReturn($notification); |
|
75
|
|
|
$notification->markAsRead()->shouldBeCalled(); |
|
76
|
|
|
$repository->save($notification)->shouldBeCalled(); |
|
77
|
|
|
$this->__invoke($command); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.