|
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\Command\Inbox; |
|
16
|
|
|
|
|
17
|
|
|
use Kreta\Notifier\Application\Command\Inbox\ReceiveNotificationCommand; |
|
18
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\NotificationBody; |
|
19
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\NotificationId; |
|
20
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\User; |
|
21
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
22
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserRepository; |
|
23
|
|
|
use PhpSpec\ObjectBehavior; |
|
24
|
|
|
use Prophecy\Argument; |
|
25
|
|
|
|
|
26
|
|
View Code Duplication |
class ReceiveNotificationHandlerSpec extends ObjectBehavior |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
private $notificationId; |
|
29
|
|
|
private $userId; |
|
30
|
|
|
|
|
31
|
|
|
function let(UserRepository $repository, ReceiveNotificationCommand $command) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->beConstructedWith($repository); |
|
34
|
|
|
|
|
35
|
|
|
$command->notificationId()->shouldBeCalled()->willReturn('notification-id'); |
|
36
|
|
|
$command->body()->shouldBeCalled()->willReturn('The notification body'); |
|
37
|
|
|
$command->userId()->shouldBeCalled()->willReturn('user-id'); |
|
38
|
|
|
|
|
39
|
|
|
$this->notificationId = NotificationId::generate('notification-id'); |
|
40
|
|
|
$this->userId = UserId::generate('user-id'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_receives_notification( |
|
44
|
|
|
ReceiveNotificationCommand $command, |
|
45
|
|
|
UserRepository $repository, |
|
46
|
|
|
User $user |
|
47
|
|
|
) { |
|
48
|
|
|
$repository->get($this->userId)->shouldBeCalled()->willReturn($user); |
|
49
|
|
|
$user->receiveNotification($this->notificationId, Argument::type(NotificationBody::class))->shouldBeCalled(); |
|
50
|
|
|
$repository->save($user)->shouldBeCalled(); |
|
51
|
|
|
$this->__invoke($command); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
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.