|
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(); |
|
|
|
|
|
|
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
|
|
|
} |