shouldTrowErrorWhenTryingToDeleteNonExistingPost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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
    public function shouldDeleteExistingPost()
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
    public 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
}