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
|
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser; |
15
|
|
|
|
16
|
|
|
trait PostsHttpTrait |
17
|
|
|
{ |
18
|
|
|
use SerializationTrait; |
19
|
|
|
|
20
|
|
|
public function createPost(CreatePostCommand $command): CreatePostCommandResponse |
21
|
|
|
{ |
22
|
|
|
$client = $this->getClient(); |
23
|
|
|
$client->request('POST', '/api/admin/posts/', [], [], [], $this->json($command)); |
24
|
|
|
return $this->responseObject($client, CreatePostCommandResponse::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function updatePost(UpdatePostCommand $command): void |
28
|
|
|
{ |
29
|
|
|
$this->getClient()->request('PUT', '/api/admin/posts/' . $command->getId(), [], [], [], $this->json($command)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function deletePost(DeletePostCommand $command): void |
33
|
|
|
{ |
34
|
|
|
$this->getClient()->request('DELETE', '/api/admin/posts/' . $command->getId()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function findAllPosts(FindAllPostsQuery $query): Page |
38
|
|
|
{ |
39
|
|
|
$client = $this->getClient(); |
40
|
|
|
$client->request('GET', '/api/posts/?pageNo=' . $query->getPageNo()); |
41
|
|
|
return $this->responseObject($client, Page::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function findPostById(FindPostByIdQuery $query): FindPostQueryResponse |
45
|
|
|
{ |
46
|
|
|
$client = $this->getClient(); |
47
|
|
|
$client->request('GET', '/api/posts/' . $query->getId()); |
48
|
|
|
return $this->responseObject($client, FindPostQueryResponse::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return KernelBrowser |
53
|
|
|
*/ |
54
|
|
|
public abstract function getClient(): KernelBrowser; |
55
|
|
|
} |