Test Setup Failed
Push — main ( abdcb9...2e5f68 )
by Slawomir
04:37
created

shouldCreatePostHeaderUponPostCreatedIEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 21
rs 9.7998
1
<?php
2
3
namespace App\Tests\Modules\Comments\Unit;
4
5
use App\Modules\Comments\Api\Event\Inbound\PostCreatedCommentsIEvent;
6
use App\Modules\Comments\Api\Event\Inbound\PostDeletedCommentsIEvent;
7
use App\Modules\Comments\Api\Event\Inbound\PostUpdatedCommentsIEvent;
8
use App\Modules\Comments\Api\Query\FindCommentsPostHeadersQuery;
9
use App\Tests\TestUtils\Contracts\ApplicationEventContractLoader;
10
use Symfony\Component\Uid\Ulid;
11
12
class PostEventsCommentsHandlingSpec extends CommentsSpec
13
{
14
    use ApplicationEventContractLoader;
15
16
    /**
17
     * @test
18
     */
19
    public function shouldCreatePostHeaderUponPostCreatedIEvent()
20
    {
21
        //given: there was a PostCreatedIEvent to be published
22
        $event = new PostCreatedCommentsIEvent($this->getInboundEvent("Comments/PostCreatedCommentsIEvent"));
23
24
        //when: the Event was published
25
        $this->commentsApi->onPostCreated($event);
26
27
        //then: Post Header was created - no Exception was thrown
28
        $headers = $this->commentsApi->findPostHeaders(new FindCommentsPostHeadersQuery());
29
        self::assertNotNull($headers);
30
        self::assertCount(1, $headers);
31
        self::assertTrue(isset($headers[0]));
32
        self::assertEquals($event->getId(), $headers[0]->getId());
33
        self::assertEquals($event->getTitle(), $headers[0]->getTitle());
34
        self::assertEquals($event->getSummary(), $headers[0]->getSummary());
35
        self::assertEquals($event->getTags(), $headers[0]->getTags());
36
        self::assertEquals($event->getCreatedById(), $headers[0]->getCreatedById());
37
        self::assertEquals($event->getCreatedByName(), $headers[0]->getCreatedByName());
38
        self::assertEquals($event->getCreatedAt(), $headers[0]->getCreatedAt());
39
        self::assertEquals(1, $headers[0]->getVersion());
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function shouldUpdatePostHeaderUponPostUpdatedIEvent(): void
46
    {
47
        //given: there was a PostCreatedIEvent to be published
48
        $event = new PostCreatedCommentsIEvent($this->getInboundEvent("Comments/PostCreatedCommentsIEvent"));
49
50
        //and: the Event was already published
51
        $this->commentsApi->onPostCreated($event);
52
53
        //and: the Header was to be updated
54
        $event = new PostUpdatedCommentsIEvent($this->getInboundEvent("Comments/PostUpdatedCommentsIEvent"));
55
56
        //when: the Event was published
57
        $this->commentsApi->onPostUpdated($event);
58
59
        //then: Post Header was created - no Exception was thrown
60
        $headers = $this->commentsApi->findPostHeaders(new FindCommentsPostHeadersQuery());
61
        self::assertNotNull($headers);
62
        self::assertCount(1, $headers);
63
        self::assertTrue(isset($headers[0]));
64
        self::assertEquals($event->getId(), $headers[0]->getId());
65
        self::assertEquals($event->getTitle(), $headers[0]->getTitle());
66
        self::assertEquals($event->getSummary(), $headers[0]->getSummary());
67
        self::assertEquals($event->getTags(), $headers[0]->getTags());
68
        self::assertEquals($event->getLastVersion(), $headers[0]->getVersion());
69
    }
70
71
    /**
72
     * @test
73
     */
74
    public function shouldDeletePostHeaderUponPostUpdatedIEvent(): void
75
    {
76
        //given: there was a PostCreatedIEvent to be published
77
        $event = new PostCreatedCommentsIEvent($this->getInboundEvent("Comments/PostCreatedCommentsIEvent"));
78
79
        //and: the Event was already published
80
        $this->commentsApi->onPostCreated($event);
81
82
        //and: the Header was to be updated
83
        $event = new PostDeletedCommentsIEvent($this->getInboundEvent("Comments/PostDeletedCommentsIEvent"));
84
85
        //when: the Event was published
86
        $this->commentsApi->onPostDeleted($event);
87
88
        //then: Post Header was created - no Exception was thrown
89
        $headers = $this->commentsApi->findPostHeaders(new FindCommentsPostHeadersQuery());
90
        self::assertNotNull($headers);
91
        self::assertCount(0, $headers);
92
    }
93
}