Code Duplication    Length = 52-52 lines in 2 locations

Notifier/tests/Spec/Kreta/Notifier/Application/Inbox/Notification/MarkAsReadNotificationSpec.php 1 location

@@ 28-79 (lines=52) @@
25
use Kreta\Notifier\Domain\Model\Inbox\UserRepository;
26
use PhpSpec\ObjectBehavior;
27
28
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

Notifier/tests/Spec/Kreta/Notifier/Application/Inbox/Notification/MarkAsUnreadNotificationSpec.php 1 location

@@ 28-79 (lines=52) @@
25
use Kreta\Notifier\Domain\Model\Inbox\UserRepository;
26
use PhpSpec\ObjectBehavior;
27
28
class MarkAsUnreadNotificationSpec extends ObjectBehavior
29
{
30
    private $notificationId;
31
    private $userId;
32
33
    function let(
34
        NotificationRepository $repository,
35
        UserRepository $userRepository,
36
        MarkAsUnreadNotificationCommand $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_unread_notification_when_the_user_does_not_exist(
48
        MarkAsUnreadNotificationCommand $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_unread_notification_when_the_notification_does_not_exist(
56
        MarkAsUnreadNotificationCommand $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_unread_notification(
67
        MarkAsUnreadNotificationCommand $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->markAsUnread()->shouldBeCalled();
76
        $repository->save($notification)->shouldBeCalled();
77
        $this->__invoke($command);
78
    }
79
}
80