diff --git a/src/MapUpdater.php b/src/MapUpdater.php index 5683f839..e1f718a2 100644 --- a/src/MapUpdater.php +++ b/src/MapUpdater.php @@ -66,8 +66,8 @@ public function selectBaseMap(string $mapClass): MapUpdater * @return list * A list of error messages. * - * @throws \RuntimeException - * If it was not possible to access the file. + * @throws SourceUpdateException + * If it was not possible to access the source file. */ public function loadMapFromApacheFile(string $source_file): array { @@ -75,8 +75,7 @@ public function loadMapFromApacheFile(string $source_file): array $lines = @file($source_file); if ($lines == false) { - $errors[] = "Failed accessing {$source_file}"; - return $errors; + throw new SourceUpdateException("Failed accessing {$source_file}"); } $i = 1; foreach ($lines as $line) { @@ -110,6 +109,9 @@ public function loadMapFromApacheFile(string $source_file): array * * @return list * A list of error messages. + * + * @throws SourceUpdateException + * If it was not possible to access the source file. */ public function loadMapFromFreedesktopFile(string $source_file): array { @@ -117,8 +119,7 @@ public function loadMapFromFreedesktopFile(string $source_file): array $contents = @file_get_contents($source_file); if ($contents == false) { - $errors[] = 'Failed loading file ' . $source_file; - return $errors; + throw new SourceUpdateException('Failed loading file ' . $source_file); } $xml = @simplexml_load_string($contents); diff --git a/src/SourceUpdateException.php b/src/SourceUpdateException.php new file mode 100644 index 00000000..ff63f4e2 --- /dev/null +++ b/src/SourceUpdateException.php @@ -0,0 +1,10 @@ +expectException(SourceUpdateException::class); $this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/zero.mime-types.txt'); - // @phpstan-ignore method.impossibleType - $this->assertSame([], $this->newMap->getMapArray()); } public function testLoadMapFromApacheMissingFile(): void { - $this->assertSame( - ["Failed accessing certainly_missing.xml"], - $this->updater->loadMapFromApacheFile('certainly_missing.xml') - ); + $this->expectException(SourceUpdateException::class); + $this->updater->loadMapFromApacheFile('certainly_missing.txt'); } public function testApplyOverridesFailure(): void @@ -129,10 +127,8 @@ public function testLoadMapFromFreedesktopFileZeroLines(): void public function testLoadMapFromFreedesktopMissingFile(): void { - $this->assertSame( - ["Failed loading file certainly_missing.xml"], - $this->updater->loadMapFromFreedesktopFile('certainly_missing.xml') - ); + $this->expectException(SourceUpdateException::class); + $this->updater->loadMapFromFreedesktopFile('certainly_missing.xml'); } public function testLoadMapFromFreedesktopInvalidFile(): void