This is a comment on ImageMagick Support for PHP Thumb Library, posted by WikiAdmin at 06/10/2026 23:15

View source for ImageMagick Tests for PHP Thumb Library


%%(hl php)
<?php
namespace PHPThumb\Tests;

use PHPThumb\Imagick;
use PHPUnit\Framework\TestCase;

class ImagickTest extends TestCase
{
	protected Imagick $avif;
	protected Imagick $bmp;
	protected Imagick $gif;
	protected Imagick $heic;
	protected Imagick $jpg;
	protected Imagick $png;
	protected Imagick $tiff;
	protected Imagick $webp;

	protected function setUp(): void
	{
		$this->avif	= new Imagick(__DIR__ . '/../../resources/test.avif');
		$this->bmp	= new Imagick(__DIR__ . '/../../resources/test.bmp');
		$this->gif	= new Imagick(__DIR__ . '/../../resources/test.gif');
		$this->heic	= new Imagick(__DIR__ . '/../../resources/test.heic');
		$this->jpg	= new Imagick(__DIR__ . '/../../resources/test.jpg');
		$this->png	= new Imagick(__DIR__ . '/../../resources/test.png');
		$this->tiff	= new Imagick(__DIR__ . '/../../resources/test.tiff');
		$this->webp	= new Imagick(__DIR__ . '/../../resources/test.webp');
	}

	public function testLoadFileTypes()
	{
		self::assertSame('AVIF',	$this->avif->getFormat());
		self::assertSame('BMP',		$this->bmp->getFormat());
		self::assertSame('GIF',		$this->gif->getFormat());
		self::assertSame('HEIC',	$this->heic->getFormat());
		self::assertSame('JPG',		$this->jpg->getFormat());
		self::assertSame('PNG',		$this->png->getFormat());
		self::assertSame('TIFF',	$this->tiff->getFormat());
		self::assertSame('WEBP',	$this->webp->getFormat());
	}

	/**
	 * This test might seem pointless but it runs the __destruct and gets us to
	 * 100% code coverage.
	 */
	public function testImageDestroy()
	{
		$testImage = new Imagick(__DIR__ . '/../../resources/test.gif');
		unset($testImage);
		self::assertSame(false, isset($testImage));
	}

	/**
	 * This test first resize a webp image and then save it in a temp file.
	 * Load the image file and test if the resulting image have a width of 200 px.
	 */
	public function testWebp()
	{
		$this->webp->adaptiveResize(200, 200);
		$tempFile = __DIR__ . '/../../resources/imagick_resize.webp';
		fwrite(fopen($tempFile, 'w'), $this->webp->getImageAsString());
		$testing = new Imagick($tempFile);
		self::assertSame(200, $testing->getCurrentDimensions()['width']);
		unlink($tempFile);
	}
}
%%

%%(hl php)
<?php
namespace PHPThumb\Tests;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

class ImagickLoadTest extends TestCase
{
	protected Imagick $thumb;

	protected function setUp(): void
	{
		$this->thumb = new Imagick(__DIR__ . '/../../resources/test.jpg');
	}

	public function testLoadFile()
	{
		self::assertSame(['width' => 500, 'height' => 375], $this->thumb->getCurrentDimensions());
		self::assertSame([
			'resizeUp'				=> false,
			'avifQuality'			=> 100,
			'jpegQuality'			=> 100,
			'webpQuality'			=> 100,
			'correctPermissions'	=> false,
			'preserveAlpha'			=> true,
			'alphaMaskColor'		=> [
										0 => 255,
										1 => 255,
										2 => 255
			],
			'preserveTransparency'  => true,
			'transparencyMaskColor' => [
										0 => 0,
										1 => 0,
										2 => 0
			],
			'interlace'				=> null
		], $this->thumb->getOptions());

		self::assertSame('JPG', $this->thumb->getFormat());
		self::assertSame(__DIR__ . '/../../resources/test.jpg', $this->thumb->getFileName());
	}

	public function testSetFormat()
	{
		$this->thumb->setFormat('PNG');
		self::assertSame('PNG', $this->thumb->getFormat());
	}

	public function testSetFilename()
	{
		$this->thumb->setFilename('mytest.jpg');
		self::assertSame('mytest.jpg', $this->thumb->getFilename());
	}

	public function testLoadExternalImage()
	{
		$gravatarThumb = new Imagick('https://en.gravatar.com/userimage/1132703/2ccbcfbea4a1b3b8d955c1e7746b882b.jpg');
		self::assertSame(true, $gravatarThumb->getIsRemoteImage());
	}

	public function testNonexistentFile()
	{
		$this->expectException(InvalidArgumentException::class);
		$madeupThumb = new Imagick('nosuchimage.jpg');
	}

	public function testIsRemoteImage()
	{
		$remoteThumb = new Imagick('https://example.com/image.jpg');
		self::assertTrue($remoteThumb->getIsRemoteImage());

		$localThumb = new Imagick(__DIR__ . '/../../resources/test.jpg');
		self::assertFalse($localThumb->getIsRemoteImage());
	}

	public function testGettersAndSetters()
	{
		$this->thumb->setMaxWidth(100);
		$this->thumb->setMaxHeight(200);
		$this->thumb->setPercent(50);

		self::assertSame(100, $this->thumb->getMaxWidth());
		self::assertSame(200, $this->thumb->getMaxHeight());
		self::assertSame(50, $this->thumb->getPercent());

		$this->thumb->setNewDimensions(['new_width' => 250, 'new_height' => 188]);
		self::assertSame(['new_width' => 250, 'new_height' => 188], $this->thumb->getNewDimensions());
	}
}
%%

%%(hl php)
<?php
namespace PHPThumb\Tests;

use InvalidArgumentException;
use PHPThumb\Imagick;
use PHPUnit\Framework\TestCase;

class ImagickOperationsTest extends TestCase
{
	protected Imagick $thumb;

	protected function setUp(): void
	{
		$this->thumb = new Imagick(__DIR__ . '/../../resources/test.jpg');
	}

	/**
	 * @dataProvider resizeProvider
	 */
	public function testResize(int $maxWidth, int $maxHeight, array $expected): void
	{
		$result = $this->thumb->resize($maxWidth, $maxHeight);

		self::assertSame($expected['width'], $this->thumb->getCurrentDimensions()['width']);
		self::assertSame($expected['height'], $this->thumb->getCurrentDimensions()['height']);
		self::assertInstanceOf(Imagick::class, $result);
	}

	public static function resizeProvider(): array
	{
		return [
			'resize by width'  => [200, 0, ['width' => 200, 'height' => 150]],
			'resize by height' => [0, 200, ['width' => 267, 'height' => 200]],
			'resize both'      => [100, 100, ['width' => 100, 'height' => 75]],
			'no resize'        => [0, 0, ['width' => 500, 'height' => 375]],
		];
	}

	/**
	 * @dataProvider adaptiveResizeProvider
	 */
	public function testAdaptiveResize(int $width, int $height, array $expected): void
	{
		$this->thumb->adaptiveResize($width, $height);

		self::assertSame($expected['width'], $this->thumb->getCurrentDimensions()['width']);
		self::assertSame($expected['height'], $this->thumb->getCurrentDimensions()['height']);
	}

	public static function adaptiveResizeProvider(): array
	{
		return [
			'square resize'        => [200, 200, ['width' => 200, 'height' => 200]],
			'landscape resize'     => [400, 200, ['width' => 400, 'height' => 200]],
			'portrait resize'      => [200, 400, ['width' => 200, 'height' => 400]],
			'width only'           => [300, 0, ['width' => 300, 'height' => 225]],
			'height only'          => [0, 300, ['width' => 400, 'height' => 300]],
		];
	}

	public function testAdaptiveResizeInvalidArguments()
	{
		$this->expectException(InvalidArgumentException::class);
		$this->thumb->adaptiveResize(0, 0);
	}

	/**
	 * @dataProvider adaptiveResizeQuadrantProvider
	 */
	public function testAdaptiveResizeQuadrant(int $width, int $height, string $quadrant, array $expected): void
	{
		$this->thumb->adaptiveResizeQuadrant($width, $height, $quadrant);

		self::assertSame($expected['width'], $this->thumb->getCurrentDimensions()['width']);
		self::assertSame($expected['height'], $this->thumb->getCurrentDimensions()['height']);
	}

	public static function adaptiveResizeQuadrantProvider(): array
	{
		return [
			'center quadrant' => [200, 200, 'C', ['width' => 200, 'height' => 200]],
			'left quadrant'   => [200, 200, 'L', ['width' => 200, 'height' => 200]],
			'right quadrant'  => [200, 200, 'R', ['width' => 200, 'height' => 200]],
			'top quadrant'    => [200, 200, 'T', ['width' => 200, 'height' => 200]],
			'bottom quadrant' => [200, 200, 'B', ['width' => 200, 'height' => 200]],
		];
	}

	public function testAdaptiveResizePercent()
	{
		$this->thumb->adaptiveResizePercent(200, 200, 25);

		self::assertSame(200, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(200, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testResizePercent()
	{
		$this->thumb->resizePercent(50);

		self::assertSame(250, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(188, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testCrop()
	{
		$this->thumb->crop(100, 50, 200, 150);

		self::assertSame(200, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(150, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testCropFromCenter()
	{
		$this->thumb->cropFromCenter(200);

		self::assertSame(200, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(200, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testCropFromCenterWithHeight()
	{
		$this->thumb->cropFromCenter(200, 100);

		self::assertSame(200, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(100, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testRotateImageCW()
	{
		$this->thumb->rotateImage('CW');

		self::assertSame(375, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(500, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testRotateImageCCW()
	{
		$this->thumb->rotateImage('CCW');

		self::assertSame(375, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(500, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testRotateImageNDegrees()
	{
		$this->thumb->rotateImageNDegrees(180);

		self::assertSame(500, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(375, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testPad()
	{
		$this->thumb->pad(600, 500);

		self::assertSame(600, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(500, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testPadNoResize()
	{
		$pad = $this->thumb->pad(500, 375);

		self::assertSame(500, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(375, $this->thumb->getCurrentDimensions()['height']);
		self::assertInstanceOf(Imagick::class, $pad);
	}

	public function testPadWithColor()
	{
		$this->thumb->pad(600, 500, [0, 0, 0]);

		self::assertSame(600, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(500, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testSetOptions()
	{
		$options = [
			'resizeUp'          => true,
			'jpegQuality'       => 75,
			'preserveAlpha'     => false,
		];

		$result = $this->thumb->setOptions($options);

		$getOptions = $this->thumb->getOptions();
		self::assertTrue($getOptions['resizeUp']);
		self::assertSame(75, $getOptions['jpegQuality']);
		self::assertFalse($getOptions['preserveAlpha']);
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testResizeUp()
	{
		$this->thumb->setOptions(['resizeUp' => true]);
		$this->thumb->resize(600, 600);

		self::assertSame(600, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(600, $this->thumb->getCurrentDimensions()['height']);
	}

	public function testResizeUpDisabled()
	{
		$this->thumb->setOptions(['resizeUp' => false]);
		$this->thumb->resize(600, 600);

		// Should not exceed original dimensions
		self::assertSame(500, $this->thumb->getCurrentDimensions()['width']);
		self::assertSame(375, $this->thumb->getCurrentDimensions()['height']);
	}
}
%%

%%(hl php)
<?php
namespace PHPThumb\Tests;

use InvalidArgumentException;
use PHPThumb\Imagick;
use RuntimeException;
use PHPUnit\Framework\TestCase;

class ImagickOutputTest extends TestCase
{
	protected function setUp(): void
	{
		$this->thumb = new Imagick(__DIR__ . '/../../resources/test.jpg');
	}

	public function testSaveJpeg()
	{
		$tempFile = __DIR__ . '/../../resources/imagick_output.jpg';
		$this->thumb->save($tempFile);

		self::assertFileExists($tempFile);
		unlink($tempFile);
	}

	public function testSavePng()
	{
		$tempFile = __DIR__ . '/../../resources/imagick_output.png';
		$this->thumb->save($tempFile, 'PNG');

		self::assertFileExists($tempFile);
		unlink($tempFile);
	}

	public function testSaveWebp()
	{
		$tempFile = __DIR__ . '/../../resources/imagick_output.webp';
		$this->thumb->save($tempFile, 'WEBP');

		self::assertFileExists($tempFile);
		unlink($tempFile);
	}

	public function testSaveGif()
	{
		$tempFile = __DIR__ . '/../../resources/imagick_output.gif';
		$this->thumb->save($tempFile, 'GIF');

		self::assertFileExists($tempFile);
		unlink($tempFile);
	}

	public function testSaveInvalidFormat()
	{
		$this->expectException(InvalidArgumentException::class);
		$this->thumb->save('output.xyz', 'XYZ');
	}

	public function testSaveUnwritableDirectory()
	{
		$this->expectException(RuntimeException::class);
		$this->thumb->save('/nonexistent/directory/output.jpg');
	}

	public function testGetImageAsString()
	{
		$this->thumb->resize(100, 100);
		$imageData = $this->thumb->getImageAsString();

		self::assertNotEmpty($imageData);
		self::assertIsString($imageData);
	}

	public function testSaveWithQuality()
	{
		$tempFile = __DIR__ . '/../../resources/imagick_output_quality.jpg';

		$this->thumb->setOptions(['jpegQuality' => 50]);
		$this->thumb->resize(100, 100);
		$this->thumb->save($tempFile, 'JPEG');

		self::assertFileExists($tempFile);

		// File size should be smaller with lower quality
		$originalSize = filesize(__DIR__ . '/../../resources/test.jpg');
		$savedSize = filesize($tempFile);

		self::assertLessThan($originalSize, $savedSize);
		unlink($tempFile);
	}

	public function testSavePreservesFormat()
	{
		$tempFile = __DIR__ . '/../../resources/imagick_preserve.jpg';

		$this->thumb->resize(100, 100);
		$this->thumb->save($tempFile);

		$reloaded = new Imagick($tempFile);
		self::assertSame('JPG', $reloaded->getFormat());
		unlink($tempFile);
	}
}
%%

%%(hl php)
<?php
namespace PHPThumb\Tests;

use InvalidArgumentException;
use PHPThumb\Imagick;
use PHPUnit\Framework\TestCase;

class ImagickAdvancedTest extends TestCase
{
	protected function setUp(): void
	{
		$this->thumb = new Imagick(__DIR__ . '/../../resources/test.png');
	}

	/**
	 * @dataProvider formatConversionProvider
	 */
	public function testFormatConversion(string $outputFormat): void
	{
		$tempFile = __DIR__ . '/../../resources/imagick_convert.' . strtolower($outputFormat);
		$this->thumb->resize(100, 100);
		$this->thumb->save($tempFile, $outputFormat);

		self::assertFileExists($tempFile);

		$reloaded = new Imagick($tempFile);
		self::assertSame($outputFormat, $reloaded->getFormat());

		unlink($tempFile);
	}

	public static function formatConversionProvider(): array
	{
		return [
			'to JPEG' => ['JPEG'],
			'to PNG'  => ['PNG'],
			'to GIF'  => ['GIF'],
			'to WEBP' => ['WEBP'],
		];
	}

	public function testChainedOperations()
	{
		$this->thumb
			->resize(400, 300)
			->rotateImage('CW')
			->crop(50, 50, 200, 200);

		$dimensions = $this->thumb->getCurrentDimensions();

		self::assertSame(200, $dimensions['width']);
		self::assertSame(200, $dimensions['height']);
	}

	public function testMultipleRotations()
	{
		$this->thumb->rotateImage('CW');
		$this->thumb->rotateImage('CW');
		$this->thumb->rotateImage('CW');
		$this->thumb->rotateImage('CW');

		// After 4 90-degree rotations, should be back to original orientation
		$dimensions = $this->thumb->getCurrentDimensions();
		self::assertSame(500, $dimensions['width']);
		self::assertSame(375, $dimensions['height']);
	}

	public function testOldImageGetter()
	{
		$oldImage = $this->thumb->getOldImage();
		self::assertNotNull($oldImage);
	}

	public function testWorkingImageAfterResize()
	{
		$this->thumb->resize(200, 200);

		// Working image is used internally during operations
		// After resize, old_image contains the result
		$current = $this->thumb->getOldImage();
		self::assertNotNull($current);
	}

	public function testSetOldImage()
	{
		$originalImage = $this->thumb->getOldImage();
		$newImage = new \Imagick(__DIR__ . '/../../resources/test.gif');

		$this->thumb->setOldImage($newImage);

		$replacedImage = $this->thumb->getOldImage();
		self::assertNotSame($originalImage, $replacedImage);
	}

	public function testSetWorkingImage()
	{
		$newImage = new \Imagick(__DIR__ . '/../../resources/test.gif');
		$this->thumb->setWorkingImage($newImage);

		$workingImage = $this->thumb->getWorkingImage();
		self::assertNotNull($workingImage);
	}

	public function testCurrentDimensions()
	{
		$dimensions = $this->thumb->getCurrentDimensions();

		self::assertArrayHasKey('width', $dimensions);
		self::assertArrayHasKey('height', $dimensions);
		self::assertSame(500, $dimensions['width']);
		self::assertSame(375, $dimensions['height']);
	}

	public function testSetCurrentDimensions()
	{
		$newDimensions = ['width' => 100, 'height' => 100];
		$result = $this->thumb->setCurrentDimensions($newDimensions);

		self::assertSame($newDimensions, $this->thumb->getCurrentDimensions());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testNewDimensions()
	{
		$this->thumb->resize(200, 150);

		$newDimensions = $this->thumb->getNewDimensions();
		self::assertArrayHasKey('new_width', $newDimensions);
		self::assertArrayHasKey('new_height', $newDimensions);
	}

	public function testSetNewDimensions()
	{
		$newDimensions = ['new_width' => 150, 'new_height' => 150];
		$result = $this->thumb->setNewDimensions($newDimensions);

		self::assertSame($newDimensions, $this->thumb->getNewDimensions());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testMaxWidthSetter()
	{
		$result = $this->thumb->setMaxWidth(300);
		self::assertSame(300, $this->thumb->getMaxWidth());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testMaxHeightSetter()
	{
		$result = $this->thumb->setMaxHeight(300);
		self::assertSame(300, $this->thumb->getMaxHeight());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testPercentSetter()
	{
		$result = $this->thumb->setPercent(75);
		self::assertSame(75, $this->thumb->getPercent());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testGetFilename()
	{
		self::assertSame(__DIR__ . '/../../resources/test.png', $this->thumb->getFilename());
	}

	public function testSetFilename()
	{
		$result = $this->thumb->setFilename('new_filename.png');
		self::assertSame('new_filename.png', $this->thumb->getFilename());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testGetFormat()
	{
		self::assertSame('PNG', $this->thumb->getFormat());
	}

	public function testSetFormat()
	{
		$result = $this->thumb->setFormat('JPG');
		self::assertSame('JPG', $this->thumb->getFormat());
		self::assertInstanceOf(Imagick::class, $result);
	}

	public function testGetOptions()
	{
		$options = $this->thumb->getOptions();

		self::assertIsArray($options);
		self::assertArrayHasKey('resizeUp', $options);
		self::assertArrayHasKey('jpegQuality', $options);
	}

	public function testPreserveAlphaOption()
	{
		$this->thumb->setOptions(['preserveAlpha' => true]);
		$options = $this->thumb->getOptions();

		self::assertTrue($options['preserveAlpha']);
	}

	public function testInterlaceOption()
	{
		$this->thumb->setOptions(['interlace' => true]);
		$options = $this->thumb->getOptions();

		self::assertTrue($options['interlace']);
	}
}
%%

%%(hl php)
<?php
namespace PHPThumb\Tests;

use PHPThumb\Imagick;
use PHPUnit\Framework\TestCase;

class ImagickPluginTest extends TestCase
{
	protected function setUp(): void
	{
		$this->thumb = new Imagick(__DIR__ . '/../../resources/test.jpg');
	}

	public function testPluginsAreProcessedOnShow()
	{
		// Create a mock plugin that should be called
		$mockPlugin = new class implements \PHPThumb\PluginInterface {
			public static bool $wasCalled = false;

			public function execute(\PHPThumb\PHPThumb $phpthumb): \PHPThumb\PHPThumb
			{
				self::$wasCalled = true;
				return $phpthumb;
			}
		};

		// Store original and enable output buffering
		$originalCalled = $mockPlugin::$wasCalled;

		$thumb = new Imagick(__DIR__ . '/../../resources/test.jpg', [], [$mockPlugin]);
		$thumb->resize(100, 100);

		// Capture output
		ob_start();
		$thumb->show(true);
		$output = ob_get_clean();

		self::assertTrue($mockPlugin::$wasCalled);
		self::assertNotEmpty($output);
	}

	public function testMultiplePluginsExecuted()
	{
		$callOrder = [];

		$plugin1 = new class($callOrder, 1) implements \PHPThumb\PluginInterface {
			private array &$order;
			private int $number;

			public function __construct(array &$order, int $number)
			{
				$this->order = &$order;
				$this->number = $number;
			}

			public function execute(\PHPThumb\PHPThumb $phpthumb): \PHPThumb\PHPThumb
			{
				$this->order[] = $this->number;
				return $phpthumb;
			}
		};

		$plugin2 = new class($callOrder, 2) implements \PHPThumb\PluginInterface {
			private array &$order;
			private int $number;

			public function __construct(array &$order, int $number)
			{
				$this->order = &$order;
				$this->number = $number;
			}

			public function execute(\PHPThumb\PHPThumb $phpthumb): \PHPThumb\PHPThumb
			{
				$this->order[] = $this->number;
				return $phpthumb;
			}
		};

		$thumb = new Imagick(
			__DIR__ . '/../../resources/test.jpg',
			[],
			[$plugin1, $plugin2]
		);

		ob_start();
		$thumb->show(true);
		ob_end_clean();

		self::assertSame([1, 2], $callOrder);
	}

	public function testPluginCanModifyImage()
	{
		$plugin = new class implements \PHPThumb\PluginInterface {
			public function execute(\PHPThumb\PHPThumb $phpthumb): \PHPThumb\PHPThumb
			{
				$phpthumb->resize(50, 50);
				return $phpthumb;
			}
		};

		$thumb = new Imagick(__DIR__ . '/../../resources/test.jpg', [], [$plugin]);

		ob_start();
		$thumb->show(true);
		ob_end_clean();

		self::assertSame(50, $thumb->getCurrentDimensions()['width']);
		self::assertSame(50, $thumb->getCurrentDimensions()['height']);
	}
}
%%

%%(hl xml)
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
         cacheDirectory=".phpunit.cache"
         executionOrder="depends,defects"
         requireCoverageMetadata="false"
         beStrictAboutCoverageMetadata="false"
         beStrictAboutOutputDuringTests="true"
         failOnRisky="true"
         failOnWarning="true">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <source>
        <include>
            <directory>src</directory>
        </include>
        <exclude>
            <directory>src/Tests</directory>
        </exclude>
    </source>

    <groups>
        <exclude>
            <group>slow</group>
        </exclude>
    </groups>

    <extensions>
    </extensions>
</phpunit>
%%

%%(hl php)
<?php
namespace PHPThumb\Tests;

use PHPThumb\Imagick;
use PHPUnit\Framework\TestCase;

class ImagickRemoteImageTest extends TestCase
{
	public function testRemoteImageLoad()
	{
		// Skip if no network available
		if (!getenv('RUN_NETWORK_TESTS')) {
			$this->markTestSkipped('Network tests are disabled');
		}

		$thumb = new Imagick('https://www.php.net/images/logos/php-logo.svg');

		self::assertTrue($thumb->getIsRemoteImage());
		self::assertNotEmpty($thumb->getCurrentDimensions());
	}

	public function testRemoteImageResize()
	{
		// Skip if no network available
		if (!getenv('RUN_NETWORK_TESTS')) {
			$this->markTestSkipped('Network tests are disabled');
		}

		$thumb = new Imagick('https://www.php.net/images/logos/php-logo.svg');
		$thumb->resize(100, 100);

		self::assertSame(100, $thumb->getCurrentDimensions()['width']);
		self::assertSame(100, $thumb->getCurrentDimensions()['height']);
	}

	public function testInvalidRemoteUrl()
	{
		$this->expectException(\Exception::class);

		// This should throw an exception for invalid remote image
		new Imagick('https://invalid-domain-that-does-not-exist-12345.com/image.jpg');
	}
}
%%

=== Test Resources ===

You may need to add these test resource files to your ##./resources/## directory:
  - ##test.avif## - AVIF format test image
  - ##test.bmp## - BMP format test image  
  - ##test.heic## - HEIC format test image
  - ##test.tiff## - TIFF format test image

=== Running the Tests ===

%%(hl bash)
# Run all Imagick tests
./vendor/bin/phpunit --testsuite="Imagick" tests/ImagickTest.php

# Run specific test file
./vendor/bin/phpunit tests/ImagickTest.php

# Run with coverage
./vendor/bin/phpunit --coverage-html coverage tests/ImagickTest.php

# Run all tests including network tests
RUN_NETWORK_TESTS=1 ./vendor/bin/phpunit
%%

=== Test Categories ===

#|
*| Test File | Purpose |*
|| ##ImagickTest.php## | Basic functionality, file type loading ||
|| ##ImagickLoadTest.php## | File/remote image loading, getters/setters ||
|| ##ImagickOperationsTest.php## | Resize, crop, rotate, pad operations ||
|| ##ImagickOutputTest.php## | Save, getImageAsString, format conversion ||
|| ##ImagickAdvancedTest.php## | Chained operations, dimension management ||
|| ##ImagickPluginTest.php## | Plugin execution during show() ||
|| ##ImagickRemoteImageTest.php## | Remote URL image handling (optional) ||
|#