Skip to content

Commit 84c2c0e

Browse files
author
Your Name
committed
test: add tests for Gitea comment operations
- Implement testCreateComment with PR creation and verification - Implement testUpdateComment with comment modification flow - Add try/finally cleanup to prevent test repository leaks - Remove skipped test markers for createComment and updateComment
1 parent f29fc06 commit 84c2c0e

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
@@ -788,7 +821,39 @@ public function testGetPullRequestFromBranchNoPR(): void
788821

789822
public function testCreateComment(): void
790823
{
791-
$this->markTestSkipped('Will be implemented in follow-up PR');
824+
$repositoryName = 'test-create-comment-' . \uniqid();
825+
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
826+
827+
try {
828+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
829+
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'test-branch', 'main');
830+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test', 'Add test', 'test-branch');
831+
832+
// Create PR
833+
$pr = $this->vcsAdapter->createPullRequest(
834+
self::$owner,
835+
$repositoryName,
836+
'Test PR',
837+
'test-branch',
838+
'main'
839+
);
840+
841+
$prNumber = $pr['number'] ?? 0;
842+
$this->assertGreaterThan(0, $prNumber);
843+
844+
// Test createComment
845+
$commentId = $this->vcsAdapter->createComment(self::$owner, $repositoryName, $prNumber, 'Test comment');
846+
847+
$this->assertNotEmpty($commentId);
848+
$this->assertIsString($commentId);
849+
$this->assertIsNumeric($commentId);
850+
851+
// Verify comment was created
852+
$retrievedComment = $this->vcsAdapter->getComment(self::$owner, $repositoryName, $commentId);
853+
$this->assertSame('Test comment', $retrievedComment);
854+
} finally {
855+
$this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
856+
}
792857
}
793858

794859
public function testCreateFile(): void

0 commit comments

Comments
 (0)