Skip to content

Commit d18eda2

Browse files
authored
Merge pull request #73 from jaysomani/feat/gitea-comment-tests
test: add tests for Gitea comment operations
2 parents 2f18162 + a12ffe2 commit d18eda2

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

tests/VCS/Adapter/GiteaTest.php

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,40 @@ public function testGenerateCloneCommandWithTag(): void
505505

506506
public function testUpdateComment(): void
507507
{
508-
$this->markTestSkipped('Will be implemented in follow-up PR');
508+
$repositoryName = 'test-update-comment-' . \uniqid();
509+
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
510+
511+
try {
512+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
513+
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'test-branch', 'main');
514+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test', 'Add test', 'test-branch');
515+
516+
// Create PR
517+
$pr = $this->vcsAdapter->createPullRequest(
518+
self::$owner,
519+
$repositoryName,
520+
'Test PR',
521+
'test-branch',
522+
'main'
523+
);
524+
525+
$prNumber = $pr['number'] ?? 0;
526+
$this->assertGreaterThan(0, $prNumber);
527+
528+
// Create comment
529+
$commentId = $this->vcsAdapter->createComment(self::$owner, $repositoryName, $prNumber, 'Original comment');
530+
531+
// Test updateComment
532+
$updatedCommentId = $this->vcsAdapter->updateComment(self::$owner, $repositoryName, (int)$commentId, 'Updated comment');
533+
534+
$this->assertSame($commentId, $updatedCommentId);
535+
536+
// Verify comment was updated
537+
$finalComment = $this->vcsAdapter->getComment(self::$owner, $repositoryName, $commentId);
538+
$this->assertSame('Updated comment', $finalComment);
539+
} finally {
540+
$this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
541+
}
509542
}
510543

511544
public function testGetCommit(): void
@@ -822,7 +855,39 @@ public function testGetPullRequestFromBranchNoPR(): void
822855

823856
public function testCreateComment(): void
824857
{
825-
$this->markTestSkipped('Will be implemented in follow-up PR');
858+
$repositoryName = 'test-create-comment-' . \uniqid();
859+
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
860+
861+
try {
862+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
863+
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'test-branch', 'main');
864+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test', 'Add test', 'test-branch');
865+
866+
// Create PR
867+
$pr = $this->vcsAdapter->createPullRequest(
868+
self::$owner,
869+
$repositoryName,
870+
'Test PR',
871+
'test-branch',
872+
'main'
873+
);
874+
875+
$prNumber = $pr['number'] ?? 0;
876+
$this->assertGreaterThan(0, $prNumber);
877+
878+
// Test createComment
879+
$commentId = $this->vcsAdapter->createComment(self::$owner, $repositoryName, $prNumber, 'Test comment');
880+
881+
$this->assertNotEquals('', $commentId);
882+
$this->assertIsString($commentId);
883+
$this->assertIsNumeric($commentId);
884+
885+
// Verify comment was created
886+
$retrievedComment = $this->vcsAdapter->getComment(self::$owner, $repositoryName, $commentId);
887+
$this->assertSame('Test comment', $retrievedComment);
888+
} finally {
889+
$this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
890+
}
826891
}
827892

828893
public function testCreateFile(): void

0 commit comments

Comments
 (0)