Skip to content

Commit 1bd7ceb

Browse files
committed
test: assert HTTP status code is set on exception code in failure tests
1 parent e0578d0 commit 1bd7ceb

3 files changed

Lines changed: 30 additions & 10 deletions

File tree

tests/VCS/Adapter/GitHubTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,12 @@ public function testDeleteRepository(): void
237237

238238
public function testDeleteNonExistingRepositoryFails(): void
239239
{
240-
$this->expectException(\Exception::class);
241-
$this->vcsAdapter->deleteRepository(static::$owner, 'non-existing-repo-' . \uniqid());
240+
try {
241+
$this->vcsAdapter->deleteRepository(static::$owner, 'non-existing-repo-' . \uniqid());
242+
$this->fail('Expected exception not thrown');
243+
} catch (\Exception $e) {
244+
$this->assertGreaterThanOrEqual(400, $e->getCode());
245+
}
242246
}
243247

244248
public function testGetRepositoryName(): void

tests/VCS/Adapter/GitLabTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,14 +1198,22 @@ public function testDeleteRepositoryTwiceFails(): void
11981198
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
11991199
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
12001200

1201-
$this->expectException(\Exception::class);
1202-
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1201+
try {
1202+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1203+
$this->fail('Expected exception not thrown');
1204+
} catch (\Exception $e) {
1205+
$this->assertGreaterThanOrEqual(400, $e->getCode());
1206+
}
12031207
}
12041208

12051209
public function testDeleteNonExistingRepositoryFails(): void
12061210
{
1207-
$this->expectException(\Exception::class);
1208-
$this->vcsAdapter->deleteRepository(static::$owner, 'non-existing-repo-' . \uniqid());
1211+
try {
1212+
$this->vcsAdapter->deleteRepository(static::$owner, 'non-existing-repo-' . \uniqid());
1213+
$this->fail('Expected exception not thrown');
1214+
} catch (\Exception $e) {
1215+
$this->assertGreaterThanOrEqual(400, $e->getCode());
1216+
}
12091217
}
12101218

12111219
public function testGetPullRequestFromBranchNoPR(): void

tests/VCS/Adapter/GiteaTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,14 +1203,22 @@ public function testDeleteRepositoryTwiceFails(): void
12031203
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
12041204
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
12051205

1206-
$this->expectException(\Exception::class);
1207-
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1206+
try {
1207+
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
1208+
$this->fail('Expected exception not thrown');
1209+
} catch (\Exception $e) {
1210+
$this->assertGreaterThanOrEqual(400, $e->getCode());
1211+
}
12081212
}
12091213

12101214
public function testDeleteNonExistingRepositoryFails(): void
12111215
{
1212-
$this->expectException(\Exception::class);
1213-
$this->vcsAdapter->deleteRepository(static::$owner, 'non-existing-repo-' . \uniqid());
1216+
try {
1217+
$this->vcsAdapter->deleteRepository(static::$owner, 'non-existing-repo-' . \uniqid());
1218+
$this->fail('Expected exception not thrown');
1219+
} catch (\Exception $e) {
1220+
$this->assertGreaterThanOrEqual(400, $e->getCode());
1221+
}
12141222
}
12151223

12161224
public function testGetOwnerName(): void

0 commit comments

Comments
 (0)