Skip to content

Commit

Permalink
Add method Format::mediaType()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Oct 6, 2024
1 parent cfa0986 commit 4a5a7f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ public function mediaTypes(): array
});
}

/**
* Return the first found media type for the current format
*
* @return MediaType
*/
public function mediaType(): MediaType
{
$types = $this->mediaTypes();

return reset($types);
}

/**
* Return the possible file extension for the current format
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function testMediaTypesJpeg(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(4, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_JPEG, $format->mediaType());
}

public function testMediaTypesWebp(): void
Expand All @@ -64,6 +66,8 @@ public function testMediaTypesWebp(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(2, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_WEBP, $format->mediaType());
}

public function testMediaTypesFGif(): void
Expand All @@ -72,6 +76,8 @@ public function testMediaTypesFGif(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(1, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_GIF, $format->mediaType());
}

public function testMediaTypesPng(): void
Expand All @@ -80,6 +86,8 @@ public function testMediaTypesPng(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(2, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_PNG, $format->mediaType());
}

public function testMediaTypesAvif(): void
Expand All @@ -88,6 +96,8 @@ public function testMediaTypesAvif(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(2, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_AVIF, $format->mediaType());
}

public function testMediaTypesBmp(): void
Expand All @@ -96,6 +106,8 @@ public function testMediaTypesBmp(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(8, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_BMP, $format->mediaType());
}

public function testMediaTypesTiff(): void
Expand All @@ -104,6 +116,8 @@ public function testMediaTypesTiff(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(1, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_TIFF, $format->mediaType());
}

public function testMediaTypesJpeg2000(): void
Expand All @@ -112,6 +126,8 @@ public function testMediaTypesJpeg2000(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(3, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_JP2, $format->mediaType());
}

public function testMediaTypesHeic(): void
Expand All @@ -120,6 +136,8 @@ public function testMediaTypesHeic(): void
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(3, $mediaTypes);

$this->assertEquals(MediaType::IMAGE_HEIC, $format->mediaType());
}

public function testEncoderJpeg(): void
Expand Down

0 comments on commit 4a5a7f6

Please sign in to comment.