Skip to content

Commit

Permalink
Restore full test coverage (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondrake authored Dec 30, 2024
1 parent 7c7c2ff commit 49d60ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/src/MapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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());

Expand Down Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions tests/src/MapUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 49d60ef

Please sign in to comment.