UserIncrementCommentCountWhenCommentPostedTest.php
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace FootyRoom\Tests\Integration\User;
use FootyRoom\Core\Comment\Author;
use FootyRoom\Core\Comment\Comment;
use FootyRoom\Core\Comment\CommentPosted;
use FootyRoom\Core\ForumPost\ForumPost;
use FootyRoom\Core\Wall\Wall;
use FootyRoom\Core\User\IncrementCommentCountWhenCommentPosted;
use FootyRoom\Repositories\UserRepository;
use FootyRoom\Tests\TestCase;
class UserIncrementCommentCountWhenCommentPostedTest extends TestCase
{
public function setup()
{
$this->mockUserRepository = $this->getMockBuilder(UserRepository::class)
->disableOriginalConstructor()
->getMock();
$this->incrementPostCountWhenForumPostPosted = new IncrementCommentCountWhenCommentPosted(
$this->mockUserRepository
);
}
public function testIncrementCommentCountWillNotBeCalledIfPostIsInstanceofWall()
{
$postId = 1;
$author = new Author(41301, 'chanBC');
$content = 'test content';
$html = '';
$comment = new Comment(
$postId,
$author,
$content,
$html
);
$userId = 41301;
$username = 'Denis';
$wall = new Wall(
$userId,
$username
);
$commentPosted = new CommentPosted($comment, $wall);
$this->mockUserRepository->expects($this->never())
->method('incrementCommentCount');
$this->incrementPostCountWhenForumPostPosted->handle($commentPosted);
}
public function testIncrementCommentCountWillNotBeCalledIfAuthorIsNotMember()
{
$postId = 1;
$author = new Author('', 'chanBC');
$content = 'test content';
$html = '';
$comment = new Comment(
$postId,
$author,
$content,
$html
);
$title = 'title';
$categoryId = 61;
$userId = '';
$forumPost = new ForumPost(
$title,
$categoryId,
$userId
);
$commentPosted = new CommentPosted($comment, $forumPost);
$this->mockUserRepository->expects($this->never())
->method('incrementCommentCount');
$this->incrementPostCountWhenForumPostPosted->handle($commentPosted);
}
public function testIncrementCommentCountWasCalled()
{
$postId = 1;
$author = new Author(41301, 'chanBC');
$content = 'test content';
$html = '';
$comment = new Comment(
$postId,
$author,
$content,
$html
);
$title = 'title';
$categoryId = 61;
$userId = 41301;
$forumPost = new ForumPost(
$title,
$categoryId,
$userId
);
$commentPosted = new CommentPosted($comment, $forumPost);
$this->mockUserRepository->expects($this->once())
->method('incrementCommentCount');
$this->incrementPostCountWhenForumPostPosted->handle($commentPosted);
}
}