|
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\Query\FindAllPostsQuery; |
|
7
|
|
|
use App\Modules\Posts\Api\Query\FindPostByIdQuery; |
|
8
|
|
|
use App\Modules\Posts\Domain\Repository\PostsFindingRepositoryInterface; |
|
9
|
|
|
|
|
10
|
|
|
class PostFindingSpec extends PostsSpec |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @test |
|
15
|
|
|
*/ |
|
16
|
|
|
public function shouldFindExistingPost() |
|
17
|
|
|
{ |
|
18
|
|
|
//given: there is a new Blog Post already created |
|
19
|
|
|
$command = new CreatePostCommand('Post Title', 'Post Body', ['t1', 't2']); |
|
20
|
|
|
$createResponse = $this->postsApi->createPost($command); |
|
21
|
|
|
|
|
22
|
|
|
//and: the Post is to be found |
|
23
|
|
|
$query = new FindPostByIdQuery($createResponse->getId()); |
|
24
|
|
|
|
|
25
|
|
|
//when: the Post is found |
|
26
|
|
|
$findResponse = $this->postsApi->findPostById($query); |
|
27
|
|
|
|
|
28
|
|
|
//then: the Post was found |
|
29
|
|
|
self::assertNotNull($findResponse); |
|
30
|
|
|
self::assertEquals($createResponse->getId(), $findResponse->getId()); |
|
31
|
|
|
self::assertEquals('Post Title', $findResponse->getTitle()); |
|
32
|
|
|
self::assertEquals('Post Body', $findResponse->getBody()); |
|
33
|
|
|
self::assertEquals(['t1', 't2'], $findResponse->getTags()); |
|
34
|
|
|
self::assertNotNull($findResponse->getCreatedById()); |
|
35
|
|
|
self::assertNotNull($findResponse->getCreatedByName()); |
|
36
|
|
|
self::assertNotNull($findResponse->getCreatedAt()); |
|
37
|
|
|
self::assertNotNull($findResponse->getUpdatedAt()); |
|
38
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @test |
|
43
|
|
|
*/ |
|
44
|
|
|
public function shouldFindAllPosts() |
|
45
|
|
|
{ |
|
46
|
|
|
//given: there is a new Blog Post already created |
|
47
|
|
|
$command = new CreatePostCommand('Post Title', 'Post Body', ['t1', 't2']); |
|
48
|
|
|
$createResponse = $this->postsApi->createPost($command); |
|
49
|
|
|
|
|
50
|
|
|
//and: the Post is to be found |
|
51
|
|
|
$query = new FindAllPostsQuery(1); |
|
52
|
|
|
|
|
53
|
|
|
//when: the Post is found |
|
54
|
|
|
$findResponse = $this->postsApi->findAllPosts($query); |
|
55
|
|
|
|
|
56
|
|
|
//then: the Post was found |
|
57
|
|
|
self::assertNotNull($findResponse); |
|
58
|
|
|
self::assertNotNull($findResponse->getData()); |
|
59
|
|
|
self::assertEquals(PostsFindingRepositoryInterface::PAGE_SIZE, $findResponse->getPageSize()); |
|
60
|
|
|
self::assertEquals(1, $findResponse->getCount()); |
|
61
|
|
|
self::assertEquals(1, $findResponse->getPageNo()); |
|
62
|
|
|
self::assertCount(1, $findResponse->getData()); |
|
63
|
|
|
self::assertTrue(isset($findResponse->getData()[0])); |
|
64
|
|
|
|
|
65
|
|
|
$postHeader = $findResponse->getData()[0]; |
|
66
|
|
|
|
|
67
|
|
|
self::assertEquals($createResponse->getId(), $postHeader->getId()); |
|
68
|
|
|
self::assertEquals('Post Title', $postHeader->getTitle()); |
|
69
|
|
|
self::assertEquals('Post Body', $postHeader->getSummary()); |
|
70
|
|
|
self::assertEquals(['t1', 't2'], $postHeader->getTags()); |
|
71
|
|
|
self::assertEquals(0, $postHeader->getCommentsCount()); |
|
72
|
|
|
self::assertNotNull($postHeader->getCreatedById()); |
|
73
|
|
|
self::assertNotNull($postHeader->getCreatedByName()); |
|
74
|
|
|
self::assertNotNull($postHeader->getCreatedAt()); |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
} |