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

PostsHttpTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createPost() 0 5 1
A deletePost() 0 3 1
A findPostById() 0 5 1
A findAllPosts() 0 5 1
A updatePost() 0 3 1
1
<?php
2
3
namespace App\Tests\Modules\Posts\Integration\Http;
4
5
use App\Infrastructure\Pagination\Page;
6
use App\Modules\Posts\Api\Command\CreatePostCommand;
7
use App\Modules\Posts\Api\Command\DeletePostCommand;
8
use App\Modules\Posts\Api\Command\Response\CreatePostCommandResponse;
9
use App\Modules\Posts\Api\Command\UpdatePostCommand;
10
use App\Modules\Posts\Api\Query\FindAllPostsQuery;
11
use App\Modules\Posts\Api\Query\FindPostByIdQuery;
12
use App\Modules\Posts\Api\Query\Response\FindPostQueryResponse;
13
use App\Tests\TestUtils\SerializationTrait;
14
15
trait PostsHttpTrait
16
{
17
    use SerializationTrait;
18
19
    public function createPost(CreatePostCommand $command): CreatePostCommandResponse
20
    {
21
        $client = $this->getClient();
0 ignored issues
show
Bug introduced by
It seems like getClient() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        /** @scrutinizer ignore-call */ 
22
        $client = $this->getClient();
Loading history...
22
        $client->request('POST', '/api/admin/posts/', [], [], [], $this->json($command));
23
        return $this->responseObject($client, CreatePostCommandResponse::class);
24
    }
25
26
    public function updatePost(UpdatePostCommand $command): void
27
    {
28
        $this->getClient()->request('PUT', '/api/admin/posts/' . $command->getId(), [], [], [], $this->json($command));
29
    }
30
31
    public function deletePost(DeletePostCommand $command): void
32
    {
33
        $this->getClient()->request('DELETE', '/api/admin/posts/' . $command->getId());
34
    }
35
36
    public function findAllPosts(FindAllPostsQuery $query): Page
37
    {
38
        $client = $this->getClient();
39
        $client->request('GET', '/api/posts/?pageNo=' . $query->getPageNo());
40
        return $this->responseObject($client, Page::class);
41
    }
42
43
    public function findPostById(FindPostByIdQuery $query): FindPostQueryResponse
44
    {
45
        $client = $this->getClient();
46
        $client->request('GET', '/api/posts/' . $query->getId());
47
        return $this->responseObject($client, FindPostQueryResponse::class);
48
    }
49
}