1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 09:10:21 +02:00

Allow all driver namespaces

This commit is contained in:
Oliver Vogel
2025-07-30 15:13:19 +02:00
committed by GitHub
parent a1e382ec49
commit 8c49eb21a6
5 changed files with 144 additions and 11 deletions

View File

@@ -5,15 +5,27 @@ declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd;
use Generator;
use Intervention\Image\Analyzers\WidthAnalyzer as GenericWidthAnalyzer;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
use Intervention\Image\Decoders\FilePathImageDecoder as GenericFilePathImageDecoder;
use Intervention\Image\Drivers\Gd\Analyzers\WidthAnalyzer;
use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Drivers\Gd\Encoders\PngEncoder;
use Intervention\Image\Drivers\Gd\Modifiers\ResizeModifier;
use Intervention\Image\Encoders\PngEncoder as GenericPngEncoder;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\FileExtension;
use Intervention\Image\Format;
use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorProcessorInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializableInterface;
use Intervention\Image\MediaType;
use Intervention\Image\Modifiers\ResizeModifier as GenericResizeModifier;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
@@ -211,4 +223,55 @@ final class DriverTest extends BaseTestCase
{
$this->assertTrue(is_string($this->driver->version()));
}
#[DataProvider('spezializeDataProvider')]
public function testSpecialize(string $inputClassname, string $outputClassname): void
{
$this->assertInstanceOf($outputClassname, $this->driver->specialize(new $inputClassname()));
}
public static function spezializeDataProvider(): Generator
{
// specializing possible
yield [GenericResizeModifier::class, ResizeModifier::class];
yield [GenericWidthAnalyzer::class, WidthAnalyzer::class];
yield [GenericPngEncoder::class, PngEncoder::class];
yield [GenericFilePathImageDecoder::class, FilePathImageDecoder::class];
// already specialized
yield [ResizeModifier::class, ResizeModifier::class];
yield [WidthAnalyzer::class, WidthAnalyzer::class];
yield [PngEncoder::class, PngEncoder::class];
yield [FilePathImageDecoder::class, FilePathImageDecoder::class];
}
public function testSpecializeFailure(): void
{
$this->expectException(NotSupportedException::class);
$this->driver->specialize(new class () implements AnalyzerInterface, SpecializableInterface
{
protected DriverInterface $driver;
public function analyze(ImageInterface $image): mixed
{
return true;
}
/** @return array<string, mixed> **/
public function specializable(): array
{
return [];
}
public function setDriver(DriverInterface $driver): SpecializableInterface
{
return $this;
}
public function driver(): DriverInterface
{
return $this->driver;
}
});
}
}