|
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\Model\Inbox\Notification; |
|
16
|
|
|
|
|
17
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\Notification; |
|
18
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationBody; |
|
19
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationId; |
|
20
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationMarkedAsRead; |
|
21
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationMarkedAsUnread; |
|
22
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationPublished; |
|
23
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
24
|
|
|
use Kreta\SharedKernel\Domain\Model\AggregateRoot; |
|
25
|
|
|
use Kreta\SharedKernel\Domain\Model\DomainEventCollection; |
|
26
|
|
|
use Kreta\SharedKernel\Domain\Model\EventSourcedAggregateRoot; |
|
27
|
|
|
use Kreta\SharedKernel\Event\EventStream; |
|
28
|
|
|
use PhpSpec\ObjectBehavior; |
|
29
|
|
|
|
|
30
|
|
|
class NotificationSpec extends ObjectBehavior |
|
31
|
|
|
{ |
|
32
|
|
|
function let(NotificationId $id, UserId $userId, NotificationBody $body) |
|
33
|
|
|
{ |
|
34
|
|
|
$id->id()->willReturn('notification-id'); |
|
35
|
|
|
$this->beConstructedBroadcast($id, $userId, $body); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_can_be_broadcast(NotificationId $id, UserId $userId, NotificationBody $body) |
|
39
|
|
|
{ |
|
40
|
|
|
$id->id()->willReturn('notification-id'); |
|
41
|
|
|
$this->beConstructedBroadcast($id, $userId, $body); |
|
42
|
|
|
$this->shouldHaveType(Notification::class); |
|
43
|
|
|
$this->shouldHaveType(AggregateRoot::class); |
|
44
|
|
|
$this->shouldImplement(EventSourcedAggregateRoot::class); |
|
45
|
|
|
$this->id()->shouldReturn($id); |
|
46
|
|
|
$id->id()->shouldBeCalled()->willReturn('notification-id'); |
|
47
|
|
|
$this->__toString()->shouldReturn('notification-id'); |
|
48
|
|
|
$this->shouldHavePublished(NotificationPublished::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
View Code Duplication |
function it_can_be_reconstituted_notification( |
|
|
|
|
|
|
52
|
|
|
EventStream $stream, |
|
53
|
|
|
NotificationId $id, |
|
54
|
|
|
NotificationPublished $notificationPublished, |
|
55
|
|
|
DomainEventCollection $collection |
|
56
|
|
|
) { |
|
57
|
|
|
$collection->toArray()->shouldBeCalled()->willReturn([ |
|
58
|
|
|
$notificationPublished, |
|
59
|
|
|
]); |
|
60
|
|
|
$stream->events()->shouldBeCalled()->willReturn($collection); |
|
61
|
|
|
$stream->aggregateRootId()->shouldBeCalled()->willReturn($id); |
|
62
|
|
|
$this->beConstructedReconstitute($stream); |
|
63
|
|
|
$this->id()->shouldReturn($id); |
|
64
|
|
|
$id->id()->shouldBeCalled()->willReturn('notification-id'); |
|
65
|
|
|
$this->__toString()->shouldReturn('notification-id'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function it_marks_as_read() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->markAsRead(); |
|
71
|
|
|
$this->shouldHavePublished(NotificationMarkedAsRead::class); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
function it_marks_as_unread() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->markAsUnread(); |
|
77
|
|
|
$this->shouldHavePublished(NotificationMarkedAsUnread::class); |
|
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.