diff --git a/tests/src/MapHandlerTest.php b/tests/src/MapHandlerTest.php index 7309913b..0fe3546c 100644 --- a/tests/src/MapHandlerTest.php +++ b/tests/src/MapHandlerTest.php @@ -4,6 +4,8 @@ use FileEye\MimeMap\Extension; use FileEye\MimeMap\MalformedTypeException; +use FileEye\MimeMap\Map\DefaultMap; +use FileEye\MimeMap\Map\EmptyMap; use FileEye\MimeMap\Map\MimeMapInterface; use FileEye\MimeMap\MapHandler; use FileEye\MimeMap\MappingException; @@ -21,6 +23,15 @@ public function setUp(): void $this->map = MapHandler::map(); } + public function testSetDefaultMapClass(): void + { + MapHandler::setDefaultMapClass(EmptyMap::class); + $this->assertInstanceOf(EmptyMap::class, MapHandler::map()); + MapHandler::setDefaultMapClass(DefaultMap::class); + // @phpstan-ignore method.impossibleType + $this->assertInstanceOf(DefaultMap::class, MapHandler::map()); + } + public function testMap(): void { $this->assertStringContainsString('DefaultMap.php', $this->map->getFileName()); @@ -37,8 +48,10 @@ public function testAdd(): void { // Adding a new type with a new extension. $this->map->addTypeExtensionMapping('bingo/bongo', 'bngbng'); + $this->map->addTypeDescription('bingo/bongo', 'Bingo, Bongo!'); $this->assertSame(['bngbng'], (new Type('bingo/bongo'))->getExtensions()); $this->assertSame('bngbng', (new Type('bingo/bongo'))->getDefaultExtension()); + $this->assertSame('Bingo, Bongo!', (new Type('bingo/bongo'))->getDescription()); $this->assertSame(['bingo/bongo'], (new Extension('bngbng'))->getTypes()); $this->assertSame('bingo/bongo', (new Extension('bngbng'))->getDefaultType()); @@ -190,6 +203,14 @@ public function testSetExtensionDefaultType(): void $this->assertSame(['image/vnd.dvb.subtitle', 'text/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('SUB'))->getTypes()); } + public function testAddAliasToType(): void + { + $this->assertSame(['image/psd', 'image/x-psd', 'image/photoshop', 'image/x-photoshop', 'application/photoshop', 'application/x-photoshop',], (new Type('image/vnd.adobe.photoshop'))->getAliases()); + $this->map->addTypeAlias('image/vnd.adobe.photoshop', 'application/x-foo-bar'); + $this->assertSame(['image/psd', 'image/x-psd', 'image/photoshop', 'image/x-photoshop', 'application/photoshop', 'application/x-photoshop', 'application/x-foo-bar',], (new Type('image/vnd.adobe.photoshop'))->getAliases()); + $this->assertContains('application/x-foo-bar', $this->map->listAliases()); + } + public function testReAddAliasToType(): void { $this->assertSame(['image/psd', 'image/x-psd', 'image/photoshop', 'image/x-photoshop', 'application/photoshop', 'application/x-photoshop',], (new Type('image/vnd.adobe.photoshop'))->getAliases()); diff --git a/tests/src/MapUpdaterTest.php b/tests/src/MapUpdaterTest.php index 921ac7c3..f7b36daf 100644 --- a/tests/src/MapUpdaterTest.php +++ b/tests/src/MapUpdaterTest.php @@ -171,6 +171,22 @@ public function testWriteMapToPhpClassFile(): void $this->fileSystem->remove(__DIR__ . '/../fixtures/MiniMap.php'); } + public function testWriteMapToPhpClassFileFailure(): void + { + $this->fileSystem->copy(__DIR__ . '/../fixtures/MiniMap.php.test', __DIR__ . '/../fixtures/MiniMap.php'); + include_once(__DIR__ . '/../fixtures/MiniMap.php'); + // @phpstan-ignore class.notFound, argument.type + MapHandler::setDefaultMapClass(MiniMap::class); + $map_a = MapHandler::map(); + $this->assertStringContainsString('fixtures/MiniMap.php', $map_a->getFileName()); + $content = file_get_contents($map_a->getFileName()); + assert(is_string($content)); + $this->assertStringNotContainsString('text/plain', $content); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Failed loading file foo://bar.stub"); + $this->updater->writeMapToPhpClassFile("foo://bar.stub"); + } + public function testGetDefaultMapBuildFile(): void { $this->assertStringContainsString('default_map_build.yml', MapUpdater::getDefaultMapBuildFile());