Skip to content

Commit cf6f384

Browse files
committed
throw if DB version isn't known
1 parent bb8d713 commit cf6f384

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

app/Services/MediaWikiHostResolver.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Services;
44

55
use App\Wiki;
6+
use Exception;
67

78
class MediaWikiHostResolver {
89
// TODO: Move this mapping to a config file that doesn't require updating this code when doing a MW update?
@@ -29,6 +30,11 @@ public function getMwVersionForDomain(string $domain): string {
2930
->pluck('version')
3031
->first();
3132

32-
return self::DB_VERSION_TO_MW_VERSION[$dbVersion];
33+
if (array_key_exists($dbVersion, self::DB_VERSION_TO_MW_VERSION)) {
34+
return self::DB_VERSION_TO_MW_VERSION[$dbVersion];
35+
}
36+
throw new UnknownDBVersionException;
3337
}
3438
}
39+
40+
class UnknownDBVersionException extends Exception {}

tests/Services/MediaWikiHostResolverTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests;
44

55
use App\Services\MediaWikiHostResolver;
6+
use App\Services\UnknownDBVersionException;
67
use App\Wiki;
78
use App\WikiDb;
89
use Faker\Factory;
@@ -34,6 +35,12 @@ private function createWiki(string $domain, string $version) {
3435
}
3536

3637
public function testResolverThrowsIfUnableToFindHostInMap(): void {
37-
$this->assertTrue(true);
38+
$domain = (new Factory)->create()->unique()->text(30);
39+
$this->createWiki($domain, 'mw1.39-unmapped');
40+
$resolver = new MediaWikiHostResolver;
41+
$this->assertThrows(
42+
fn () => $resolver->getBackendHostForDomain($domain),
43+
UnknownDBVersionException::class
44+
);
3845
}
3946
}

0 commit comments

Comments
 (0)