Skip to content

Commit bbbb5f9

Browse files
committed
Restore accidentally removed check run tests
1 parent c9482b4 commit bbbb5f9

1 file changed

Lines changed: 283 additions & 0 deletions

File tree

tests/VCS/Adapter/GitHubTest.php

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,4 +870,287 @@ public function testUpdateComment(): void
870870
{
871871
$this->markTestSkipped('Requires existing PR — createPullRequest not implemented in GitHub adapter');
872872
}
873+
874+
public function testCreateCheckRun(): void
875+
{
876+
$repositoryName = 'test-create-check-run-' . \uniqid();
877+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
878+
879+
try {
880+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test');
881+
$commit = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
882+
$commitHash = $commit['commitHash'];
883+
884+
$checkRun = $this->vcsAdapter->createCheckRun(
885+
owner: static::$owner,
886+
repositoryName: $repositoryName,
887+
headSha: $commitHash,
888+
name: 'ci/build',
889+
status: 'in_progress',
890+
startedAt: gmdate('Y-m-d\TH:i:s\Z'),
891+
);
892+
893+
$this->assertArrayHasKey('id', $checkRun);
894+
$this->assertIsInt($checkRun['id']);
895+
$this->assertEquals('ci/build', $checkRun['name']);
896+
$this->assertEquals('in_progress', $checkRun['status']);
897+
$this->assertNull($checkRun['conclusion']);
898+
$this->assertEquals($commitHash, $checkRun['head_sha']);
899+
$this->assertNotEmpty($checkRun['url']);
900+
$this->assertNotEmpty($checkRun['html_url']);
901+
$this->assertNotEmpty($checkRun['started_at']);
902+
$this->assertNull($checkRun['completed_at']);
903+
904+
$fetched = $this->vcsAdapter->getCheckRun(static::$owner, $repositoryName, $checkRun['id']);
905+
$this->assertEquals($checkRun['id'], $fetched['id']);
906+
$this->assertEquals('ci/build', $fetched['name']);
907+
$this->assertEquals('in_progress', $fetched['status']);
908+
$this->assertNull($fetched['conclusion']);
909+
$this->assertEquals($commitHash, $fetched['head_sha']);
910+
$this->assertNotEmpty($fetched['url']);
911+
$this->assertNotEmpty($fetched['html_url']);
912+
} finally {
913+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
914+
}
915+
}
916+
917+
public function testCreateCheckRunWithInvalidRepository(): void
918+
{
919+
$this->expectException(\Exception::class);
920+
$this->vcsAdapter->createCheckRun(
921+
owner: static::$owner,
922+
repositoryName: 'non-existing-repository-' . \uniqid(),
923+
headSha: 'a' . str_repeat('0', 39),
924+
name: 'ci/build',
925+
);
926+
}
927+
928+
public function testGetCheckRunWithInvalidId(): void
929+
{
930+
$repositoryName = 'test-get-check-run-invalid-' . \uniqid();
931+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
932+
933+
try {
934+
$this->expectException(\Exception::class);
935+
$this->vcsAdapter->getCheckRun(static::$owner, $repositoryName, 999999999);
936+
} finally {
937+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
938+
}
939+
}
940+
941+
public function testCreateTwoCheckRunsOnSameCommit(): void
942+
{
943+
$repositoryName = 'test-two-check-runs-same-commit-' . \uniqid();
944+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
945+
946+
try {
947+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test');
948+
$commit = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
949+
$commitHash = $commit['commitHash'];
950+
951+
$first = $this->vcsAdapter->createCheckRun(
952+
owner: static::$owner,
953+
repositoryName: $repositoryName,
954+
headSha: $commitHash,
955+
name: 'ci/build',
956+
status: 'in_progress',
957+
);
958+
959+
$second = $this->vcsAdapter->createCheckRun(
960+
owner: static::$owner,
961+
repositoryName: $repositoryName,
962+
headSha: $commitHash,
963+
name: 'ci/build',
964+
status: 'in_progress',
965+
);
966+
967+
$this->assertArrayHasKey('id', $first);
968+
$this->assertArrayHasKey('id', $second);
969+
$this->assertNotEquals($first['id'], $second['id']);
970+
$this->assertEquals($commitHash, $first['head_sha']);
971+
$this->assertEquals($commitHash, $second['head_sha']);
972+
$this->assertEquals('ci/build', $first['name']);
973+
$this->assertEquals('ci/build', $second['name']);
974+
} finally {
975+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
976+
}
977+
}
978+
979+
public function testCreateCheckRunsWithSameNameOnDifferentCommits(): void
980+
{
981+
$repositoryName = 'test-check-runs-different-commits-' . \uniqid();
982+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
983+
984+
try {
985+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test');
986+
$commit1 = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
987+
$commitHash1 = $commit1['commitHash'];
988+
989+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'second.md', '# Second');
990+
$commit2 = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
991+
$commitHash2 = $commit2['commitHash'];
992+
993+
$first = $this->vcsAdapter->createCheckRun(
994+
owner: static::$owner,
995+
repositoryName: $repositoryName,
996+
headSha: $commitHash1,
997+
name: 'ci/build',
998+
status: 'in_progress',
999+
);
1000+
1001+
$second = $this->vcsAdapter->createCheckRun(
1002+
owner: static::$owner,
1003+
repositoryName: $repositoryName,
1004+
headSha: $commitHash2,
1005+
name: 'ci/build',
1006+
status: 'in_progress',
1007+
);
1008+
1009+
$this->assertArrayHasKey('id', $first);
1010+
$this->assertArrayHasKey('id', $second);
1011+
$this->assertNotEquals($first['id'], $second['id']);
1012+
$this->assertEquals($commitHash1, $first['head_sha']);
1013+
$this->assertEquals($commitHash2, $second['head_sha']);
1014+
$this->assertEquals('ci/build', $first['name']);
1015+
$this->assertEquals('ci/build', $second['name']);
1016+
} finally {
1017+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1018+
}
1019+
}
1020+
1021+
public function testCreateCheckRunCompleted(): void
1022+
{
1023+
$repositoryName = 'test-create-check-run-completed-' . \uniqid();
1024+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
1025+
1026+
try {
1027+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test');
1028+
$commit = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
1029+
$commitHash = $commit['commitHash'];
1030+
1031+
$checkRun = $this->vcsAdapter->createCheckRun(
1032+
owner: static::$owner,
1033+
repositoryName: $repositoryName,
1034+
headSha: $commitHash,
1035+
name: 'ci/build',
1036+
conclusion: 'success',
1037+
title: 'Build passed',
1038+
summary: 'All checks passed successfully.',
1039+
);
1040+
1041+
$this->assertArrayHasKey('id', $checkRun);
1042+
$this->assertIsInt($checkRun['id']);
1043+
$this->assertEquals('ci/build', $checkRun['name']);
1044+
$this->assertEquals('completed', $checkRun['status']);
1045+
$this->assertEquals('success', $checkRun['conclusion']);
1046+
$this->assertEquals($commitHash, $checkRun['head_sha']);
1047+
$this->assertNotEmpty($checkRun['url']);
1048+
$this->assertNotEmpty($checkRun['html_url']);
1049+
$this->assertNotEmpty($checkRun['completed_at']);
1050+
$this->assertEquals('Build passed', $checkRun['output']['title']);
1051+
$this->assertEquals('All checks passed successfully.', $checkRun['output']['summary']);
1052+
} finally {
1053+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1054+
}
1055+
}
1056+
1057+
public function testUpdateCheckRun(): void
1058+
{
1059+
$repositoryName = 'test-update-check-run-' . \uniqid();
1060+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
1061+
1062+
try {
1063+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test');
1064+
$commit = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
1065+
$commitHash = $commit['commitHash'];
1066+
1067+
$checkRun = $this->vcsAdapter->createCheckRun(
1068+
owner: static::$owner,
1069+
repositoryName: $repositoryName,
1070+
headSha: $commitHash,
1071+
name: 'ci/build',
1072+
status: 'in_progress',
1073+
startedAt: gmdate('Y-m-d\TH:i:s\Z'),
1074+
);
1075+
1076+
$this->assertArrayHasKey('id', $checkRun);
1077+
$this->assertEquals('in_progress', $checkRun['status']);
1078+
1079+
$updated = $this->vcsAdapter->updateCheckRun(
1080+
owner: static::$owner,
1081+
repositoryName: $repositoryName,
1082+
checkRunId: $checkRun['id'],
1083+
status: 'completed',
1084+
conclusion: 'neutral',
1085+
title: 'Deployment skipped',
1086+
summary: 'Deployment skipped because the branch does not match the configured branch triggers.',
1087+
completedAt: gmdate('Y-m-d\TH:i:s\Z'),
1088+
);
1089+
1090+
$this->assertEquals($checkRun['id'], $updated['id']);
1091+
$this->assertEquals('completed', $updated['status']);
1092+
$this->assertEquals('neutral', $updated['conclusion']);
1093+
} finally {
1094+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1095+
}
1096+
}
1097+
1098+
public function testUpdateCheckRunWithInvalidRepository(): void
1099+
{
1100+
$this->expectException(\Exception::class);
1101+
$this->vcsAdapter->updateCheckRun(
1102+
owner: static::$owner,
1103+
repositoryName: 'non-existing-repository-' . \uniqid(),
1104+
checkRunId: 999999999,
1105+
conclusion: 'success',
1106+
);
1107+
}
1108+
1109+
public function testUpdateCheckRunWithInvalidId(): void
1110+
{
1111+
$repositoryName = 'test-update-check-run-invalid-' . \uniqid();
1112+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
1113+
1114+
try {
1115+
$this->expectException(\Exception::class);
1116+
$this->vcsAdapter->updateCheckRun(
1117+
owner: static::$owner,
1118+
repositoryName: $repositoryName,
1119+
checkRunId: 999999999,
1120+
conclusion: 'success',
1121+
);
1122+
} finally {
1123+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1124+
}
1125+
}
1126+
1127+
public function testUpdateCheckRunWithMissingConclusion(): void
1128+
{
1129+
$repositoryName = 'test-update-check-run-no-conclusion-' . \uniqid();
1130+
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
1131+
1132+
try {
1133+
$this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test');
1134+
$commit = $this->vcsAdapter->getLatestCommit(static::$owner, $repositoryName, static::$defaultBranch);
1135+
$commitHash = $commit['commitHash'];
1136+
1137+
$checkRun = $this->vcsAdapter->createCheckRun(
1138+
owner: static::$owner,
1139+
repositoryName: $repositoryName,
1140+
headSha: $commitHash,
1141+
name: 'ci/build',
1142+
status: 'in_progress',
1143+
);
1144+
1145+
$this->expectException(\Exception::class);
1146+
$this->vcsAdapter->updateCheckRun(
1147+
owner: static::$owner,
1148+
repositoryName: $repositoryName,
1149+
checkRunId: $checkRun['id'],
1150+
status: 'completed',
1151+
);
1152+
} finally {
1153+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1154+
}
1155+
}
8731156
}

0 commit comments

Comments
 (0)