Update tests and Throw InvalidArgumentException when building an empty comment body

This commit is contained in:
Alex
2026-10-01 11:26:19 +03:00
parent 093fafaff4
commit 21f6cb9e83
4 changed files with 223 additions and 4 deletions
+52
View File
@@ -1382,6 +1382,21 @@ final class ApiTest extends TestCase
$this->assertSame([], $this->api->getComments('mid.post'));
}
#[Test]
public function getCommentsTreatsEmptyCommentIdsListAsNoFilter(): void
{
$this->clientMock->expects($this->once())
->method('request')
->with('GET', '/messages/mid.post/comments', [])
->willReturn(['messages' => []]);
$this->modelFactoryMock->expects($this->once())
->method('createCommentMessages')
->willReturn([]);
$this->assertSame([], $this->api->getComments('mid.post', []));
}
#[Test]
public function getCommentByIdRequestsTheSingleComment(): void
{
@@ -1427,6 +1442,21 @@ final class ApiTest extends TestCase
$this->assertSame($expectedComment, $result);
}
#[Test]
public function sendCommentOmitsDisableLinkPreviewWhenFalse(): void
{
$this->clientMock->expects($this->once())
->method('request')
->with('POST', '/messages/mid.post/comments', [], ['text' => 'Nice post'])
->willReturn(['message' => $this->commentData()]);
$this->modelFactoryMock->expects($this->once())
->method('createCommentMessageFromSendResponse')
->willReturn($this->comment());
$this->api->sendComment('mid.post', 'Nice post');
}
#[Test]
public function editCommentPutsNewTextForTheComment(): void
{
@@ -1445,6 +1475,28 @@ final class ApiTest extends TestCase
$this->assertSame($expectedResult, $this->api->editComment('mid.post', 'mid.comment', 'Edited'));
}
#[Test]
public function sendCommentWithoutAnyFieldThrowsInvalidArgumentException(): void
{
$this->clientMock->expects($this->never())->method('request');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At least one of $text, $format or $link must be provided');
$this->api->sendComment('mid.post');
}
#[Test]
public function editCommentWithoutAnyFieldThrowsInvalidArgumentException(): void
{
$this->clientMock->expects($this->never())->method('request');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At least one of $text, $format or $link must be provided');
$this->api->editComment('mid.post', 'mid.comment');
}
#[Test]
public function deleteCommentDeletesByCommentId(): void
{