@@ -62,7 +62,9 @@ public function testCreateShouldReturnErrorWhenCreatingErrored(): void
6262 $ post = $ this ->createMock (PostRepositoryInterface::class);
6363 $ post ->method ('create ' )->willReturn (false );
6464 $ post ->method ('getErrors ' )->willReturn ([1 ]);
65- $ result = $ this ->service ->create ($ post , $ author , $ this ->createMock (ThreadRepositoryInterface::class));
65+ $ thread = $ this ->createMock (ThreadRepositoryInterface::class);
66+ $ thread ->method ('isLocked ' )->willReturn (false );
67+ $ result = $ this ->service ->create ($ post , $ author , $ thread );
6668
6769 self ::assertFalse ($ result ->getResult ());
6870 self ::assertSame ([1 ], $ result ->getErrors ());
@@ -84,6 +86,20 @@ public function testCreateShouldReturnErrorWhenAuthorIsBanned(): void
8486 self ::assertSame (['api ' => 'member.banned ' ], $ result ->getErrors ());
8587 }
8688
89+ public function testCreateShouldReturnErrorWhenThreadIsLocked (): void
90+ {
91+ $ this ->transaction ->expects (self ::once ())->method ('rollBack ' );
92+
93+ $ author = $ this ->createMock (MemberRepositoryInterface::class);
94+ $ author ->method ('isBanned ' )->willReturn (false );
95+ $ thread = $ this ->createMock (ThreadRepositoryInterface::class);
96+ $ thread ->method ('isLocked ' )->willReturn (true );
97+ $ result = $ this ->service ->create ($ this ->createMock (PostRepositoryInterface::class), $ author , $ thread );
98+
99+ self ::assertFalse ($ result ->getResult ());
100+ self ::assertSame (['api ' => 'thread.locked ' ], $ result ->getErrors ());
101+ }
102+
87103 public function testCreateShouldReturnSuccessWhenCreatingIsDone (): void
88104 {
89105 $ this ->transaction ->expects (self ::once ())->method ('commit ' );
@@ -94,6 +110,7 @@ public function testCreateShouldReturnSuccessWhenCreatingIsDone(): void
94110 $ post ->method ('create ' )->willReturn (true );
95111 $ thread = $ this ->createMock (ThreadRepositoryInterface::class);
96112 $ thread ->method ('updateCounters ' )->with (1 )->willReturn (true );
113+ $ thread ->method ('isLocked ' )->willReturn (false );
97114 $ forum = $ this ->createMock (ForumRepositoryInterface::class);
98115 $ forum ->method ('updateCounters ' )->with (0 , 1 )->willReturn (true );
99116 $ thread ->method ('getParent ' )->willReturn ($ forum );
@@ -119,7 +136,9 @@ static function (array $data) {
119136 $ author ->method ('isBanned ' )->willReturn (false );
120137 $ post = $ this ->createMock (PostRepositoryInterface::class);
121138 $ post ->method ('create ' )->willThrowException (new Exception ('exc ' ));
122- $ result = $ this ->service ->create ($ post , $ author , $ this ->createMock (ThreadRepositoryInterface::class));
139+ $ thread = $ this ->createMock (ThreadRepositoryInterface::class);
140+ $ thread ->method ('isLocked ' )->willReturn (false );
141+ $ result = $ this ->service ->create ($ post , $ author , $ thread );
123142
124143 self ::assertFalse ($ result ->getResult ());
125144 self ::assertSame ('exc ' , $ result ->getErrors ()['exception ' ]->getMessage ());
@@ -135,6 +154,7 @@ public function testCreateShouldReturnErrorWhenUpdatingThreadCountersErrored():
135154 $ post ->method ('create ' )->willReturn (true );
136155 $ thread = $ this ->createMock (ThreadRepositoryInterface::class);
137156 $ thread ->method ('updateCounters ' )->willReturn (false );
157+ $ thread ->method ('isLocked ' )->willReturn (false );
138158 $ result = $ this ->service ->create ($ post , $ author , $ thread );
139159
140160 self ::assertFalse ($ result ->getResult ());
@@ -151,6 +171,7 @@ public function testCreateShouldReturnErrorWhenUpdatingForumCountersErrored(): v
151171 $ post ->method ('create ' )->willReturn (true );
152172 $ thread = $ this ->createMock (ThreadRepositoryInterface::class);
153173 $ thread ->method ('updateCounters ' )->willReturn (true );
174+ $ thread ->method ('isLocked ' )->willReturn (false );
154175 $ forum = $ this ->createMock (ForumRepositoryInterface::class);
155176 $ forum ->method ('updateCounters ' )->willReturn (false );
156177 $ thread ->method ('getParent ' )->willReturn ($ forum );
0 commit comments