mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 09:10:21 +02:00
Add new method Format::fileExtension()
This commit is contained in:
@@ -115,6 +115,18 @@ enum Format
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the first found file extension for the current format
|
||||||
|
*
|
||||||
|
* @return FileExtension
|
||||||
|
*/
|
||||||
|
public function fileExtension(): FileExtension
|
||||||
|
{
|
||||||
|
$extensions = $this->fileExtensions();
|
||||||
|
|
||||||
|
return reset($extensions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an encoder instance with given options that matches the format
|
* Create an encoder instance with given options that matches the format
|
||||||
*
|
*
|
||||||
|
@@ -193,4 +193,94 @@ final class FormatTest extends BaseTestCase
|
|||||||
$format = Format::HEIC;
|
$format = Format::HEIC;
|
||||||
$this->assertInstanceOf(HeicEncoder::class, $format->encoder());
|
$this->assertInstanceOf(HeicEncoder::class, $format->encoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsJpeg(): void
|
||||||
|
{
|
||||||
|
$format = Format::JPEG;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(2, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::JPG, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsWebp(): void
|
||||||
|
{
|
||||||
|
$format = Format::WEBP;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(1, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::WEBP, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsGif(): void
|
||||||
|
{
|
||||||
|
$format = Format::GIF;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(1, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::GIF, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsPng(): void
|
||||||
|
{
|
||||||
|
$format = Format::PNG;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(1, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::PNG, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsAvif(): void
|
||||||
|
{
|
||||||
|
$format = Format::AVIF;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(1, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::AVIF, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsBmp(): void
|
||||||
|
{
|
||||||
|
$format = Format::BMP;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(1, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::BMP, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsTiff(): void
|
||||||
|
{
|
||||||
|
$format = Format::TIFF;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(2, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::TIF, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsJp2(): void
|
||||||
|
{
|
||||||
|
$format = Format::JP2;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(8, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::JP2, $format->fileExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFileExtensionsHeic(): void
|
||||||
|
{
|
||||||
|
$format = Format::HEIC;
|
||||||
|
$extensions = $format->fileExtensions();
|
||||||
|
$this->assertIsArray($extensions);
|
||||||
|
$this->assertCount(2, $extensions);
|
||||||
|
|
||||||
|
$this->assertEquals(FileExtension::HEIC, $format->fileExtension());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user