From 85e997ea2c1e660a548212f5408387912a946fc1 Mon Sep 17 00:00:00 2001 From: mondrake Date: Fri, 14 Mar 2025 09:11:26 +0100 Subject: [PATCH 1/3] fix --- src/MapUpdater.php | 13 +++++++------ src/SourceUpdateException.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/SourceUpdateException.php 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 @@ + Date: Fri, 14 Mar 2025 09:17:24 +0100 Subject: [PATCH 2/3] fixes --- tests/fixtures/MiniMap.php | 67 ++++++++++++++++++++++++++++++++++++ tests/src/MapUpdaterTest.php | 16 ++++----- 2 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/MiniMap.php diff --git a/tests/fixtures/MiniMap.php b/tests/fixtures/MiniMap.php new file mode 100644 index 00000000..dc016f5f --- /dev/null +++ b/tests/fixtures/MiniMap.php @@ -0,0 +1,67 @@ +>>> + */ + // phpcs:disable + protected static $map = array ( + 't' => + array ( + 'application/andrew-inset' => + array ( + 'desc' => + array ( + 0 => 'ATK inset', + 1 => 'ATK: Andrew Toolkit', + ), + 'e' => + array ( + 0 => 'ez', + ), + ), + ), + 'e' => + array ( + 'ez' => + array ( + 't' => + array ( + 0 => 'application/andrew-inset', + ), + ), + ), +); + // phpcs:enable +} diff --git a/tests/src/MapUpdaterTest.php b/tests/src/MapUpdaterTest.php index f7b36daf..19d669f7 100644 --- a/tests/src/MapUpdaterTest.php +++ b/tests/src/MapUpdaterTest.php @@ -7,6 +7,7 @@ use FileEye\MimeMap\Map\MiniMap; use FileEye\MimeMap\MapHandler; use FileEye\MimeMap\MapUpdater; +use FileEye\MimeMap\SourceUpdateException; use PHPUnit\Framework\Attributes\BackupStaticProperties; use PHPUnit\Framework\Attributes\CoversClass; @@ -57,17 +58,14 @@ public function testLoadMapFromApacheFile(): void public function testLoadMapFromApacheFileZeroLines(): void { + $this->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 From 29dc569fa521ce587ed723f19d703ba09a5a440b Mon Sep 17 00:00:00 2001 From: mondrake Date: Fri, 14 Mar 2025 09:20:47 +0100 Subject: [PATCH 3/3] fix --- tests/fixtures/MiniMap.php | 67 -------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 tests/fixtures/MiniMap.php diff --git a/tests/fixtures/MiniMap.php b/tests/fixtures/MiniMap.php deleted file mode 100644 index dc016f5f..00000000 --- a/tests/fixtures/MiniMap.php +++ /dev/null @@ -1,67 +0,0 @@ ->>> - */ - // phpcs:disable - protected static $map = array ( - 't' => - array ( - 'application/andrew-inset' => - array ( - 'desc' => - array ( - 0 => 'ATK inset', - 1 => 'ATK: Andrew Toolkit', - ), - 'e' => - array ( - 0 => 'ez', - ), - ), - ), - 'e' => - array ( - 'ez' => - array ( - 't' => - array ( - 0 => 'application/andrew-inset', - ), - ), - ), -); - // phpcs:enable -}