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

PostDeletionSpec   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldDeleteExistingPost() 0 24 1
A shouldTrowErrorWhenTryingToDeleteNonExistingPost() 0 7 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\Command\DeletePostCommand;
7
use App\Modules\Posts\Api\Query\FindPostByIdQuery;
8
use App\Modules\Posts\Domain\Event\Outbound\PostDeletedOEvent;
9
use App\Tests\TestUtils\Events\InMemoryEventPublisher;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
use Symfony\Component\Uid\Ulid;
12
13
class PostDeletionSpec extends PostsSpec
14
{
15
16
    /**
17
     * @test
18
     */
19
    function shouldDeleteExistingPost()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
    {
21
        //given: there is a new Blog Post already created
22
        $command = new CreatePostCommand('Post Title', 'Post Body', ['t1', 't2']);
23
        $createResponse = $this->postsApi->createPost($command);
24
25
        //and: the Post is to be deleted
26
        $command = new DeletePostCommand($createResponse->getId());
27
28
        //when: the Post is deleted
29
        $this->postsApi->deletePost($command);
30
31
        //then: the Post was deleted correctly
32
        $findResponse = $this->postsApi->findPostById(new FindPostByIdQuery($createResponse->getId()));
33
        self::assertNull($findResponse);
34
35
        //and: a Post Created Output Event was Published
36
        $events = InMemoryEventPublisher::get(PostDeletedOEvent::class);
37
        self::assertCount(1, $events);
38
39
        //and: The Event has the correct data
40
        InMemoryEventPublisher::assertEventData([
41
            'id' => $createResponse->getId()
42
        ], $events[0]);
43
44
45
    }
46
47
    /**
48
     * @test
49
     */
50
    function shouldTrowErrorWhenTryingToDeleteNonExistingPost()
51
    {
52
        //expect: a Not Found Error
53
        $this->expectException(NotFoundHttpException::class);
54
55
        //when: the not-existent Post is deleted
56
        $this->postsApi->deletePost(new DeletePostCommand(new Ulid()));
57
    }
58
59
}