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

CommentsEvensPostsHandlingSpec   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldUpdateExistingPostWithComment() 0 24 1
1
<?php
2
3
namespace App\Tests\Modules\Posts\Unit;
4
5
use App\Modules\Posts\Api\Command\CreatePostCommand;
6
use App\Modules\Posts\Api\Event\Inbound\CommentCreatedPostsIEvent;
7
use App\Modules\Posts\Api\Query\FindPostByIdQuery;
8
use App\Tests\TestUtils\Contracts\ApplicationEventContractLoader;
9
10
class CommentsEvensPostsHandlingSpec extends PostsSpec
11
{
12
13
    use ApplicationEventContractLoader;
14
15
    /**
16
     * @test
17
     */
18
    public function shouldUpdateExistingPostWithComment()
19
    {
20
        //given: there is a new Blog Post already created
21
        $command = new CreatePostCommand('Post Title', 'Post Body', ['t1', 't2']);
22
        $createResponse = $this->postsApi->createPost($command);
23
24
        //and: There was a Comment Created
25
        $data = $this->getInboundEvent("Posts/CommentCreatedPostsIEvent");
26
        $data['postId'] = $createResponse->getId();
27
        $event = new CommentCreatedPostsIEvent($data);
28
29
        //when: the Comment Created Event is handled
30
        $this->postsApi->onCommentCreated($event);
31
32
        //and: User fetches the Post
33
        $findResponse = $this->postsApi->findPostById(new FindPostByIdQuery($createResponse->getId()));
34
35
        //then: Previously created Post is fetched with the Comment
36
        self::assertNotNull($findResponse);
37
        self::assertEquals($createResponse->getId(), $findResponse->getId());
38
        self::assertCount(1, $findResponse->getComments());
39
        self::assertEquals('Comment Author', $findResponse->getComments()[0]['author']);
40
        self::assertEquals('Comment Body', $findResponse->getComments()[0]['body']);
41
        self::assertNull($findResponse->getComments()[0]['parentId']);
42
    }
43
44
}