repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/FontProcessorTest.php
tests/Unit/Drivers/Imagick/FontProcessorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use Intervention\Image\Drivers\Imagick\FontProcessor; use Intervention\Image\Geometry\Point; use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; use Intervention\Image\Typography\TextBlock; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('imagick')] #[CoversClass(FontProcessor::class)] final class FontProcessorTest extends BaseTestCase { public function testBoxSizeTtf(): void { $processor = new FontProcessor(); $size = $processor->boxSize( 'ABC', $this->testFont()->setSize(120), ); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertEquals(163, $size->width()); $this->assertEquals(72, $size->height()); } public function testNativeFontSize(): void { $processor = new FontProcessor(); $font = new Font(); $font->setSize(14.2); $size = $processor->nativeFontSize($font); $this->assertEquals(14.2, $size); } public function testTextBlock(): void { $processor = new FontProcessor(); $result = $processor->textBlock( 'test', $this->testFont(), new Point(0, 0), ); $this->assertInstanceOf(TextBlock::class, $result); } public function testTypographicalSize(): void { $processor = new FontProcessor(); $result = $processor->typographicalSize($this->testFont()); $this->assertEquals(7, $result); } public function testCapHeight(): void { $processor = new FontProcessor(); $result = $processor->capHeight($this->testFont()); $this->assertEquals(7, $result); } public function testLeading(): void { $processor = new FontProcessor(); $result = $processor->leading($this->testFont()); $this->assertEquals(9, $result); } private function testFont(): Font { return new Font($this->getTestResourcePath('test.ttf')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/CoreTest.php
tests/Unit/Drivers/Imagick/CoreTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use Imagick; use ImagickPixel; use Intervention\Image\Drivers\Imagick\Core; use Intervention\Image\Drivers\Imagick\Frame; use Intervention\Image\Exceptions\AnimationException; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('imagick')] #[CoversClass(Core::class)] final class CoreTest extends BaseTestCase { protected Core $core; protected function setUp(): void { $imagick = new Imagick(); $im = new Imagick(); $im->newImage(10, 10, new ImagickPixel('red')); $imagick->addImage($im); $im = new Imagick(); $im->newImage(10, 10, new ImagickPixel('green')); $imagick->addImage($im); $im = new Imagick(); $im->newImage(10, 10, new ImagickPixel('blue')); $imagick->addImage($im); $this->core = new Core($imagick); } public function testAdd(): void { $imagick = new Imagick(); $imagick->newImage(100, 100, new ImagickPixel('red')); $this->assertEquals(3, $this->core->count()); $result = $this->core->add(new Frame($imagick)); $this->assertEquals(4, $this->core->count()); $this->assertInstanceOf(Core::class, $result); } public function testCount(): void { $this->assertEquals(3, $this->core->count()); } public function testIterator(): void { foreach ($this->core as $frame) { $this->assertInstanceOf(Frame::class, $frame); } } public function testNative(): void { $this->assertInstanceOf(Imagick::class, $this->core->native()); } public function testSetNative(): void { $imagick1 = new Imagick(); $imagick1->newImage(10, 10, new ImagickPixel('red')); $imagick2 = new Imagick(); $imagick2->newImage(10, 10, new ImagickPixel('red')); $core = new Core($imagick1); $this->assertEquals($imagick1, $core->native()); $core->setNative($imagick2); $this->assertEquals($imagick2, $core->native()); } public function testFrame(): void { $this->assertInstanceOf(Frame::class, $this->core->frame(0)); $this->assertInstanceOf(Frame::class, $this->core->frame(1)); $this->assertInstanceOf(Frame::class, $this->core->frame(2)); $this->expectException(AnimationException::class); $this->core->frame(3); } public function testSetGetLoops(): void { $this->assertEquals(0, $this->core->loops()); $result = $this->core->setLoops(12); $this->assertEquals(12, $this->core->loops()); $this->assertInstanceOf(Core::class, $result); } public function testHas(): void { $this->assertTrue($this->core->has(0)); $this->assertTrue($this->core->has(1)); $this->assertTrue($this->core->has(2)); $this->assertFalse($this->core->has(3)); } public function testPush(): void { $im = new Imagick(); $im->newImage(100, 100, new ImagickPixel('green')); $this->assertEquals(3, $this->core->count()); $result = $this->core->push(new Frame($im)); $this->assertEquals(4, $this->core->count()); $this->assertEquals(4, $result->count()); } public function testGet(): void { $this->assertInstanceOf(Frame::class, $this->core->get(0)); $this->assertInstanceOf(Frame::class, $this->core->get(1)); $this->assertInstanceOf(Frame::class, $this->core->get(2)); $this->assertNull($this->core->get(3)); $this->assertEquals('foo', $this->core->get(3, 'foo')); } public function testEmpty(): void { $result = $this->core->empty(); $this->assertEquals(0, $this->core->count()); $this->assertEquals(0, $result->count()); } public function testSlice(): void { $this->assertEquals(3, $this->core->count()); $result = $this->core->slice(1, 2); $this->assertEquals(2, $this->core->count()); $this->assertEquals(2, $result->count()); } public function testFirst(): void { $this->assertInstanceOf(Frame::class, $this->core->first()); } public function testLast(): void { $this->assertInstanceOf(Frame::class, $this->core->last()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/DriverTest.php
tests/Unit/Drivers/Imagick/DriverTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use Generator; use Intervention\Image\Analyzers\WidthAnalyzer as GenericWidthAnalyzer; use Intervention\Image\Decoders\FilePathImageDecoder as GenericFilePathImageDecoder; use Intervention\Image\Encoders\PngEncoder as GenericPngEncoder; use Intervention\Image\Modifiers\ResizeModifier as GenericResizeModifier; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; use Intervention\Image\Drivers\Imagick\Analyzers\WidthAnalyzer; use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\PngEncoder; use Intervention\Image\Drivers\Imagick\Modifiers\ResizeModifier; 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\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('imagick')] #[CoversClass(Driver::class)] final class DriverTest extends BaseTestCase { protected Driver $driver; protected function setUp(): void { $this->driver = new Driver(); } public function testId(): void { $this->assertEquals('Imagick', $this->driver->id()); } public function testCreateImage(): void { $image = $this->driver->createImage(3, 2); $this->assertInstanceOf(ImageInterface::class, $image); $this->assertEquals(3, $image->width()); $this->assertEquals(2, $image->height()); } public function testCreateAnimation(): void { $image = $this->driver->createAnimation(function ($animation): void { $animation->add($this->getTestResourcePath('red.gif'), .25); $animation->add($this->getTestResourcePath('green.gif'), .25); })->setLoops(5); $this->assertInstanceOf(ImageInterface::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertEquals(5, $image->loops()); $this->assertEquals(2, $image->count()); } public function testHandleInputImage(): void { $result = $this->driver->handleInput($this->getTestResourcePath('test.jpg')); $this->assertInstanceOf(ImageInterface::class, $result); } public function testHandleInputColor(): void { $result = $this->driver->handleInput('ffffff'); $this->assertInstanceOf(ColorInterface::class, $result); } public function testHandleInputObjects(): void { $result = $this->driver->handleInput('ffffff', [ new HexColorDecoder() ]); $this->assertInstanceOf(ColorInterface::class, $result); } public function testHandleInputClassnames(): void { $result = $this->driver->handleInput('ffffff', [ HexColorDecoder::class ]); $this->assertInstanceOf(ColorInterface::class, $result); } public function testColorProcessor(): void { $result = $this->driver->colorProcessor(new Colorspace()); $this->assertInstanceOf(ColorProcessorInterface::class, $result); } #[DataProvider('supportsDataProvider')] public function testSupports(bool $result, mixed $identifier): void { $this->assertEquals($result, $this->driver->supports($identifier)); } public static function supportsDataProvider(): Generator { yield [true, Format::JPEG]; yield [true, MediaType::IMAGE_JPEG]; yield [true, MediaType::IMAGE_JPG]; yield [true, FileExtension::JPG]; yield [true, FileExtension::JPEG]; yield [true, 'jpg']; yield [true, 'jpeg']; yield [true, 'image/jpg']; yield [true, 'image/jpeg']; yield [true, Format::WEBP]; yield [true, MediaType::IMAGE_WEBP]; yield [true, MediaType::IMAGE_X_WEBP]; yield [true, FileExtension::WEBP]; yield [true, 'webp']; yield [true, 'image/webp']; yield [true, 'image/x-webp']; yield [true, Format::GIF]; yield [true, MediaType::IMAGE_GIF]; yield [true, FileExtension::GIF]; yield [true, 'gif']; yield [true, 'image/gif']; yield [true, Format::PNG]; yield [true, MediaType::IMAGE_PNG]; yield [true, MediaType::IMAGE_X_PNG]; yield [true, FileExtension::PNG]; yield [true, 'png']; yield [true, 'image/png']; yield [true, 'image/x-png']; yield [true, Format::AVIF]; yield [true, MediaType::IMAGE_AVIF]; yield [true, MediaType::IMAGE_X_AVIF]; yield [true, FileExtension::AVIF]; yield [true, 'avif']; yield [true, 'image/avif']; yield [true, 'image/x-avif']; yield [true, Format::BMP]; yield [true, FileExtension::BMP]; yield [true, MediaType::IMAGE_BMP]; yield [true, MediaType::IMAGE_MS_BMP]; yield [true, MediaType::IMAGE_X_BITMAP]; yield [true, MediaType::IMAGE_X_BMP]; yield [true, MediaType::IMAGE_X_MS_BMP]; yield [true, MediaType::IMAGE_X_WINDOWS_BMP]; yield [true, MediaType::IMAGE_X_WIN_BITMAP]; yield [true, MediaType::IMAGE_X_XBITMAP]; yield [true, 'bmp']; yield [true, 'image/bmp']; yield [true, 'image/ms-bmp']; yield [true, 'image/x-bitmap']; yield [true, 'image/x-bmp']; yield [true, 'image/x-ms-bmp']; yield [true, 'image/x-windows-bmp']; yield [true, 'image/x-win-bitmap']; yield [true, 'image/x-xbitmap']; yield [true, Format::TIFF]; yield [true, MediaType::IMAGE_TIFF]; yield [true, FileExtension::TIFF]; yield [true, FileExtension::TIF]; yield [true, 'tif']; yield [true, 'tiff']; yield [true, 'image/tiff']; yield [true, Format::JP2]; yield [true, MediaType::IMAGE_JP2]; yield [true, MediaType::IMAGE_JPX]; yield [true, MediaType::IMAGE_JPM]; yield [true, FileExtension::TIFF]; yield [true, FileExtension::TIF]; yield [true, FileExtension::JP2]; yield [true, FileExtension::J2K]; yield [true, FileExtension::JPF]; yield [true, FileExtension::JPM]; yield [true, FileExtension::JPG2]; yield [true, FileExtension::J2C]; yield [true, FileExtension::JPC]; yield [true, FileExtension::JPX]; yield [true, 'jp2']; yield [true, 'j2k']; yield [true, 'jpf']; yield [true, 'jpm']; yield [true, 'jpg2']; yield [true, 'j2c']; yield [true, 'jpc']; yield [true, 'jpx']; yield [true, Format::HEIC]; yield [true, MediaType::IMAGE_HEIC]; yield [true, MediaType::IMAGE_HEIF]; yield [true, FileExtension::HEIC]; yield [true, FileExtension::HEIF]; yield [true, 'heic']; yield [true, 'heif']; yield [true, 'image/heic']; yield [true, 'image/heif']; yield [false, 'tga']; yield [false, 'image/tga']; yield [false, 'image/x-targa']; yield [false, 'foo']; yield [false, '']; } public function testVersion(): void { $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; } }); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\TiffEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(TiffEncoder::class)] final class TiffEncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new TiffEncoder(); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/tiff', $result); $this->assertEquals('image/tiff', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\HeicEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(HeicEncoder::class)] final class HeicEncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new HeicEncoder(75); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/heic', $result); $this->assertEquals('image/heic', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Generator; use Intervention\Image\Drivers\Imagick\Encoders\PngEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\ImagickTestCase; use Intervention\Image\Tests\Traits\CanInspectPngFormat; use PHPUnit\Framework\Attributes\DataProvider; #[RequiresPhpExtension('imagick')] #[CoversClass(PngEncoder::class)] final class PngEncoderTest extends ImagickTestCase { use CanInspectPngFormat; public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new PngEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); $this->assertEquals('image/png', $result->mimetype()); $this->assertFalse($this->isInterlacedPng($result)); } public function testEncodeInterlaced(): void { $image = $this->createTestImage(3, 2); $encoder = new PngEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); $this->assertEquals('image/png', $result->mimetype()); $this->assertTrue($this->isInterlacedPng($result)); } #[DataProvider('indexedDataProvider')] public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, string $result): void { $this->assertEquals( $result, $this->pngColorType($encoder->encode($image)), ); } public static function indexedDataProvider(): Generator { yield [ static::createTestImage(3, 2), // new new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::createTestImage(3, 2), // new new PngEncoder(indexed: true), 'indexed', ]; yield [ static::createTestImage(3, 2)->fill('ccc'), // new grayscale new PngEncoder(indexed: true), 'indexed', ]; yield [ static::readTestImage('circle.png'), // truecolor-alpha new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::readTestImage('circle.png'), // indexedcolor-alpha new PngEncoder(indexed: true), 'grayscale-alpha', // result should be 'indexed' but there seems to be no way to force this with imagick ]; yield [ static::readTestImage('tile.png'), // indexed new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::readTestImage('tile.png'), // indexed new PngEncoder(indexed: true), 'indexed', ]; yield [ static::readTestImage('test.jpg'), // jpeg new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::readTestImage('test.jpg'), // jpeg new PngEncoder(indexed: true), 'indexed', ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Encoders\BmpEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(BmpEncoder::class)] final class BmpEncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new BmpEncoder(); $result = $encoder->encode($image); $this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], $result); $this->assertEquals('image/bmp', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Decoders\FilePointerImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\JpegEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; use Intervention\Image\Tests\Traits\CanDetectProgressiveJpeg; #[RequiresPhpExtension('imagick')] #[CoversClass(JpegEncoder::class)] final class JpegEncoderTest extends ImagickTestCase { use CanDetectProgressiveJpeg; public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new JpegEncoder(75); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); $this->assertEquals('image/jpeg', $result->mimetype()); } public function testEncodeProgressive(): void { $image = $this->createTestImage(3, 2); $encoder = new JpegEncoder(progressive: true); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); $this->assertEquals('image/jpeg', $result->mimetype()); $this->assertTrue($this->isProgressiveJpeg($result)); } public function testEncodeStripExif(): void { $image = $this->readTestImage('exif.jpg'); $this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist')); $encoder = new JpegEncoder(strip: true); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); $this->assertEquals('image/jpeg', $result->mimetype()); $this->assertEmpty(exif_read_data($result->toFilePointer())['IFD0.Artist'] ?? null); } public function testEncodeStripExifKeepICCProfiles(): void { $image = $this->readTestImage('cmyk.jpg'); $this->assertNotEmpty($image->core()->native()->getImageProfiles('icc')); $encoder = new JpegEncoder(strip: true); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $decoder = new FilePointerImageDecoder(); $decoder->setDriver(new Driver()); $image = $decoder->decode($result->toFilePointer()); $this->assertNotEmpty($image->core()->native()->getImageProfiles('icc')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\Jpeg2000Encoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(Jpeg2000Encoder::class)] final class Jpeg2000EncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new Jpeg2000Encoder(75); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jp2', $result); $this->assertEquals('image/jp2', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\WebpEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(WebpEncoder::class)] final class WebpEncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new WebpEncoder(75); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/webp', $result); $this->assertEquals('image/webp', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\AvifEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(AvifEncoder::class)] final class AvifEncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new AvifEncoder(10); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/avif', $result); $this->assertEquals('image/avif', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php
tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; use Intervention\Gif\Decoder; use Intervention\Image\Drivers\Imagick\Encoders\GifEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(GifEncoder::class)] final class GifEncoderTest extends ImagickTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new GifEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); $this->assertEquals('image/gif', $result->mimetype()); $this->assertFalse( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); } public function testEncodeInterlaced(): void { $image = $this->createTestImage(3, 2); $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); } public function testEncodeInterlacedAnimation(): void { $image = $this->createTestAnimation(); $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/DataUriImageDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/DataUriImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\DataUriImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use stdClass; #[RequiresPhpExtension('imagick')] #[CoversClass(DataUriImageDecoder::class)] final class DataUriImageDecoderTest extends BaseTestCase { protected DataUriImageDecoder $decoder; protected function setUp(): void { $this->decoder = new DataUriImageDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode( sprintf('data:image/jpeg;base64,%s', base64_encode($this->getTestResourceData('blue.gif'))) ); $this->assertInstanceOf(Image::class, $result); } public function testDecoderNonString(): void { $this->expectException(DecoderException::class); $this->decoder->decode(new stdClass()); } public function testDecoderInvalid(): void { $this->expectException(DecoderException::class); $this->decoder->decode('invalid'); } public function testDecoderNonImage(): void { $this->expectException(DecoderException::class); $this->decoder->decode('data:text/plain;charset=utf-8,test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/SplFileInfoImageDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/SplFileInfoImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\SplFileInfoImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use SplFileInfo; #[RequiresPhpExtension('imagick')] #[CoversClass(SplFileInfoImageDecoder::class)] final class SplFileInfoImageDecoderTest extends BaseTestCase { public function testDecode(): void { $decoder = new SplFileInfoImageDecoder(); $decoder->setDriver(new Driver()); $result = $decoder->decode( new SplFileInfo($this->getTestResourcePath('blue.gif')) ); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/NativeObjectDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/NativeObjectDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use Imagick; use ImagickPixel; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\NativeObjectDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(NativeObjectDecoder::class)] final class NativeObjectDecoderTest extends BaseTestCase { protected NativeObjectDecoder $decoder; protected function setUp(): void { $this->decoder = new NativeObjectDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $native = new Imagick(); $native->newImage(3, 2, new ImagickPixel('red'), 'png'); $result = $this->decoder->decode($native); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[RequiresPhpExtension('imagick')] #[CoversClass(FilePathImageDecoder::class)] final class FilePathImageDecoderTest extends BaseTestCase { protected FilePathImageDecoder $decoder; protected function setUp(): void { $this->decoder = new FilePathImageDecoder(); $this->decoder->setDriver(new Driver()); } #[DataProvider('validFormatPathsProvider')] public function testDecode(string $path, bool $result): void { if ($result === false) { $this->expectException(DecoderException::class); } $result = $this->decoder->decode($path); if ($result === true) { $this->assertInstanceOf(Image::class, $result); } } public static function validFormatPathsProvider(): Generator { yield [self::getTestResourcePath('cats.gif'), true]; yield [self::getTestResourcePath('animation.gif'), true]; yield [self::getTestResourcePath('red.gif'), true]; yield [self::getTestResourcePath('green.gif'), true]; yield [self::getTestResourcePath('blue.gif'), true]; yield [self::getTestResourcePath('gradient.bmp'), true]; yield [self::getTestResourcePath('circle.png'), true]; yield ['no-path', false]; yield [str_repeat('x', PHP_MAXPATHLEN + 1), false]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/FilePointerImageDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/FilePointerImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\FilePointerImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(FilePointerImageDecoder::class)] final class FilePointerImageDecoderTest extends ImagickTestCase { public function testDecode(): void { $decoder = new FilePointerImageDecoder(); $decoder->setDriver(new Driver()); $fp = fopen($this->getTestResourcePath('test.jpg'), 'r'); $result = $decoder->decode($fp); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use Intervention\Image\Drivers\Imagick\Decoders\EncodedImageObjectDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\EncodedImage; use Intervention\Image\Image; use Intervention\Image\Tests\ImagickTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('imagick')] #[CoversClass(EncodedImageObjectDecoder::class)] class EncodedImageObjectDecoderTest extends ImagickTestCase { protected EncodedImageObjectDecoder $decoder; protected function setUp(): void { $this->decoder = new EncodedImageObjectDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode(new EncodedImage($this->getTestResourceData())); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/ImageObjectDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/ImageObjectDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Decoders\ImageObjectDecoder; use Intervention\Image\Image; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(ImageObjectDecoder::class)] final class ImageObjectDecoderTest extends ImagickTestCase { public function testDecode(): void { $decoder = new ImageObjectDecoder(); $result = $decoder->decode($this->readTestImage('blue.gif')); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/Base64ImageDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/Base64ImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\Base64ImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(Base64ImageDecoder::class)] final class Base64ImageDecoderTest extends BaseTestCase { protected Base64ImageDecoder $decoder; protected function setUp(): void { $this->decoder = new Base64ImageDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode( base64_encode($this->getTestResourceData('blue.gif')) ); $this->assertInstanceOf(Image::class, $result); } public function testDecoderInvalid(): void { $this->expectException(DecoderException::class); $this->decoder->decode('test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php
tests/Unit/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; use Intervention\Image\Drivers\Imagick\Decoders\BinaryImageDecoder; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use stdClass; #[RequiresPhpExtension('imagick')] #[CoversClass(BinaryImageDecoder::class)] final class BinaryImageDecoderTest extends BaseTestCase { protected BinaryImageDecoder $decoder; protected function setUp(): void { $this->decoder = new BinaryImageDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecodePng(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('tile.png'))); $this->assertInstanceOf(Image::class, $image); $this->assertInstanceOf(RgbColorspace::class, $image->colorspace()); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertCount(1, $image); } public function testDecodeGif(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('red.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertCount(1, $image); } public function testDecodeAnimatedGif(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('cats.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(75, $image->width()); $this->assertEquals(50, $image->height()); $this->assertCount(4, $image); } public function testDecodeJpegWithExif(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('exif.jpg'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertCount(1, $image); $this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist')); } public function testDecodeCmykImage(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('cmyk.jpg'))); $this->assertInstanceOf(Image::class, $image); $this->assertInstanceOf(CmykColorspace::class, $image->colorspace()); } public function testDecodeNonString(): void { $this->expectException(DecoderException::class); $this->decoder->decode(new stdClass()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use Intervention\Image\Drivers\Imagick\Analyzers\PixelColorAnalyzer; use Intervention\Image\Drivers\Imagick\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(PixelColorAnalyzer::class)] final class PixelColorAnalyzerTest extends ImagickTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new PixelColorAnalyzer(0, 0); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(ColorInterface::class, $result); $this->assertEquals('b4e000', $result->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use Intervention\Image\Drivers\Imagick\Analyzers\HeightAnalyzer; use Intervention\Image\Drivers\Imagick\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(HeightAnalyzer::class)] final class HeightAnalyzerTest extends ImagickTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new HeightAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertEquals(16, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/PixelColorsAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/PixelColorsAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Collection; use Intervention\Image\Drivers\Imagick\Analyzers\PixelColorsAnalyzer; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(PixelColorsAnalyzer::class)] final class PixelColorsAnalyzerTest extends ImagickTestCase { public function testAnalyzeAnimated(): void { $image = $this->readTestImage('animation.gif'); $analyzer = new PixelColorsAnalyzer(0, 0); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(Collection::class, $result); $colors = array_map(fn(ColorInterface $color) => $color->toHex(), $result->toArray()); $this->assertEquals($colors, ["394b63", "394b63", "394b63", "ffa601", "ffa601", "ffa601", "ffa601", "394b63"]); } public function testAnalyzeNonAnimated(): void { $image = $this->readTestImage('tile.png'); $analyzer = new PixelColorsAnalyzer(0, 0); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(Collection::class, $result); $this->assertInstanceOf(ColorInterface::class, $result->first()); $this->assertEquals('b4e000', $result->first()->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use Intervention\Image\Drivers\Imagick\Analyzers\ResolutionAnalyzer; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Resolution; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(ResolutionAnalyzer::class)] final class ResolutionAnalyzerTest extends ImagickTestCase { public function testAnalyze(): void { $image = $this->readTestImage('300dpi.png'); $analyzer = new ResolutionAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(Resolution::class, $result); $this->assertEquals(300, round($result->perInch()->x())); $this->assertEquals(300, round($result->perInch()->y())); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use Intervention\Image\Drivers\Imagick\Analyzers\ColorspaceAnalyzer; use Intervention\Image\Drivers\Imagick\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(ColorspaceAnalyzer::class)] final class ColorspaceAnalyzerTest extends ImagickTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new ColorspaceAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(ColorspaceInterface::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use Intervention\Image\Drivers\Imagick\Analyzers\WidthAnalyzer; use Intervention\Image\Drivers\Imagick\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(WidthAnalyzer::class)] final class WidthAnalyzerTest extends ImagickTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new WidthAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertEquals(16, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php
tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Analyzers; use Intervention\Image\Drivers\Imagick\Analyzers\ProfileAnalyzer; use Intervention\Image\Drivers\Imagick\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(ProfileAnalyzer::class)] final class ProfileAnalyzerTest extends ImagickTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new ProfileAnalyzer(); $analyzer->setDriver(new Driver()); $this->expectException(ColorException::class); $analyzer->analyze($image); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\SharpenModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\SharpenModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\SharpenModifier::class)] final class SharpenModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('60ab96', $image->pickColor(15, 14)->toHex()); $image->modify(new SharpenModifier(10)); $this->assertEquals('4faca6', $image->pickColor(15, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/DrawLineModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/DrawLineModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawLineModifier; use Intervention\Image\Geometry\Line; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\DrawLineModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawLineModifier::class)] final class DrawLineModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $line = new Line(new Point(0, 0), new Point(10, 0), 4); $line->setBackgroundColor('b53517'); $image->modify(new DrawLineModifier($line)); $this->assertEquals('b53517', $image->pickColor(0, 0)->toHex()); } public function testApplyTransparent(): void { $image = $this->createTestImage(10, 10)->fill('ff5500'); $this->assertColor(255, 85, 0, 255, $image->pickColor(5, 5)); $line = new Line(new Point(0, 5), new Point(10, 5), 4); $line->setBackgroundColor('fff4'); $image->modify(new DrawLineModifier($line)); $this->assertColor(255, 136, 77, 255, $image->pickColor(5, 5)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Exceptions\InputException; use Intervention\Image\Modifiers\QuantizeColorsModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\QuantizeColorsModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\QuantizeColorsModifier::class)] final class QuantizeColorsModifierTest extends ImagickTestCase { public function testColorChange(): void { $image = $this->readTestImage('gradient.bmp'); $this->assertEquals(15, $image->core()->native()->getImageColors()); $image->modify(new QuantizeColorsModifier(4)); $this->assertEquals(4, $image->core()->native()->getImageColors()); } public function testNoColorReduction(): void { $image = $this->readTestImage('gradient.bmp'); $this->assertEquals(15, $image->core()->native()->getImageColors()); $image->modify(new QuantizeColorsModifier(150)); $this->assertEquals(15, $image->core()->native()->getImageColors()); } public function testInvalidColorInput(): void { $image = $this->readTestImage('gradient.bmp'); $this->expectException(InputException::class); $image->modify(new QuantizeColorsModifier(0)); } public function testVerifyColorValueAfterQuantization(): void { $image = $this->createTestImage(3, 2)->fill('f00'); $image->modify(new QuantizeColorsModifier(1)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\CoverModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CoverModifier::class)] final class CoverModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new CoverModifier(100, 100, 'center')); $this->assertEquals(100, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); $this->assertTransparency($image->pickColor(90, 30)); } public function testModifyOddSize(): void { $image = $this->createTestImage(375, 250); $image->modify(new CoverModifier(240, 90, 'center')); $this->assertEquals(240, $image->width()); $this->assertEquals(90, $image->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\InvertModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\InvertModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\InvertModifier::class)] final class InvertModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); $image->modify(new InvertModifier()); $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/DrawRectangleModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/DrawRectangleModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawRectangleModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\DrawRectangleModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawRectangleModifier::class)] final class DrawRectangleModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $rectangle = new Rectangle(300, 200, new Point(14, 14)); $rectangle->setBackgroundColor('ffffff'); $image->modify(new DrawRectangleModifier($rectangle)); $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResizeCanvasRelativeModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ResizeCanvasRelativeModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResizeCanvasRelativeModifier::class)] final class ResizeCanvasRelativeModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->createTestImage(1, 1); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); } public function testModifyWithTransparency(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); $this->assertEquals(18, $image->width()); $this->assertEquals(18, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); $this->assertTransparency($image->pickColor(12, 1)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/PadModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\PadModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\PadModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\PadModifier::class)] final class PadModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('blue.gif'); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $image->modify(new PadModifier(30, 20, 'f00')); $this->assertEquals(30, $image->width()); $this->assertEquals(20, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 19)); $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 19)); $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 2)); $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 1)); $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 17)); $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 18)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 1)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 2)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 17)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 18)); $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 2)); $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 2)); $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 17)); $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 17)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/TextModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/TextModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Modifiers\TextModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Interfaces\ColorInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; use Intervention\Image\Typography\Font; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\TextModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\TextModifier::class)] final class TextModifierTest extends ImagickTestCase { public function testTextColor(): void { $font = (new Font())->setColor('ff0055'); $modifier = new class ('test', new Point(), $font) extends TextModifier { public function test(): ColorInterface { return $this->textColor(); } }; $modifier->setDriver(new Driver()); $this->assertInstanceOf(ColorInterface::class, $modifier->test()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/RemoveAnimationModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/RemoveAnimationModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Exceptions\InputException; use Intervention\Image\Modifiers\RemoveAnimationModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\RemoveAnimationModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\RemoveAnimationModifier::class)] final class RemoveAnimationModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('animation.gif'); $this->assertEquals(8, count($image)); $result = $image->modify(new RemoveAnimationModifier(2)); $this->assertEquals(1, count($image)); $this->assertEquals(1, count($result)); } public function testApplyPercent(): void { $image = $this->readTestImage('animation.gif'); $this->assertEquals(8, count($image)); $result = $image->modify(new RemoveAnimationModifier('20%')); $this->assertEquals(1, count($image)); $this->assertEquals(1, count($result)); } public function testApplyNonAnimated(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals(1, count($image)); $result = $image->modify(new RemoveAnimationModifier()); $this->assertEquals(1, count($image)); $this->assertEquals(1, count($result)); } public function testApplyInvalid(): void { $image = $this->readTestImage('animation.gif'); $this->expectException(InputException::class); $image->modify(new RemoveAnimationModifier('test')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ContainModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ContainModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ContainModifier::class)] final class ContainModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $result = $image->modify(new ContainModifier(200, 100, 'ff0')); $this->assertEquals(200, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(0, 0, 0, 0, $image->pickColor(140, 10)); $this->assertColor(255, 255, 0, 255, $image->pickColor(175, 10)); $this->assertEquals(200, $result->width()); $this->assertEquals(100, $result->height()); $this->assertColor(255, 255, 0, 255, $result->pickColor(0, 0)); $this->assertColor(0, 0, 0, 0, $result->pickColor(140, 10)); $this->assertColor(255, 255, 0, 255, $result->pickColor(175, 10)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/DrawPixelModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/DrawPixelModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawPixelModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\DrawPixelModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawPixelModifier::class)] final class DrawPixelModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new DrawPixelModifier(new Point(14, 14), 'ffffff')); $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use Intervention\Image\Colors\Cmyk\Colorspace; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\CropModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\CropModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CropModifier::class)] final class CropModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $image = $image->modify(new CropModifier(200, 200, 0, 0, 'ffffff', 'bottom-right')); $this->assertEquals(200, $image->width()); $this->assertEquals(200, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5)); $this->assertColor(255, 0, 0, 255, $image->pickColor(100, 100)); $this->assertColor(255, 0, 0, 255, $image->pickColor(190, 190)); } public function testModifyExtend(): void { $image = $this->readTestImage('blocks.png'); $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000', 'top-left')); $this->assertEquals(800, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(9, 9)); $this->assertColor(0, 0, 255, 255, $image->pickColor(16, 16)); $this->assertColor(0, 0, 255, 255, $image->pickColor(445, 16)); $this->assertTransparency($image->pickColor(460, 16)); } public function testModifySinglePixel(): void { $image = $this->createTestImage(1, 1); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new CropModifier(3, 3, 0, 0, 'ff0', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); } public function testModifyKeepsColorspace(): void { $image = $this->readTestImage('cmyk.jpg'); $this->assertInstanceOf(Colorspace::class, $image->colorspace()); $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000')); $this->assertInstanceOf(Colorspace::class, $image->colorspace()); } public function testModifyKeepsResolution(): void { $image = $this->readTestImage('300dpi.png'); $this->assertEquals(300, round($image->resolution()->perInch()->x())); $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000')); $this->assertEquals(300, round($image->resolution()->perInch()->x())); } public function testHalfTransparent(): void { $image = $this->createTestImage(16, 16); $image->modify(new CropModifier(32, 32, 0, 0, '00f5', 'center')); $this->assertEquals(32, $image->width()); $this->assertEquals(32, $image->height()); $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 5)); $this->assertColor(0, 0, 255, 77, $image->pickColor(16, 5)); $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 5)); $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 16)); $this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16)); $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 16)); $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 30)); $this->assertColor(0, 0, 255, 77, $image->pickColor(16, 30)); $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 30)); } public function testMergeTransparentBackgrounds(): void { $image = $this->createTestImage(1, 1)->fill('f00'); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new CropModifier(3, 3, 0, 0, '00f7', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(0, 0, 255, 127, $image->pickColor(0, 0), 1); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(0, 0, 255, 127, $image->pickColor(2, 2), 1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ColorizeModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ColorizeModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ColorizeModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ColorizeModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ColorizeModifier::class)] final class ColorizeModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('tile.png'); $image = $image->modify(new ColorizeModifier(100, -100, -100)); $this->assertColor(251, 0, 0, 255, $image->pickColor(5, 5)); $this->assertColor(239, 0, 0, 255, $image->pickColor(15, 15)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/StripMetaModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/StripMetaModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(StripMetaModifier::class)] final class StripMetaModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('exif.jpg'); $this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist')); $image->modify(new StripMetaModifier()); $this->assertNull($image->exif('IFD0.Artist')); $result = $image->toJpeg(); $this->assertEmpty(exif_read_data($result->toFilePointer())['IFD0.Artist'] ?? null); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ResolutionModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ResolutionModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResolutionModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ResolutionModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResolutionModifier::class)] final class ResolutionModifierTest extends ImagickTestCase { public function testResolutionChange(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals(72.0, $image->resolution()->x()); $this->assertEquals(72.0, $image->resolution()->y()); $image->modify(new ResolutionModifier(1, 2)); $this->assertEquals(1.0, $image->resolution()->x()); $this->assertEquals(2.0, $image->resolution()->y()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/BrightnessModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/BrightnessModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\BrightnessModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\BrightnessModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\BrightnessModifier::class)] final class BrightnessModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new BrightnessModifier(30)); $this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/DrawPolygonModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/DrawPolygonModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawPolygonModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Polygon; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\DrawPolygonModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawPolygonModifier::class)] final class DrawPolygonModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $drawable = new Polygon([new Point(0, 0), new Point(15, 15), new Point(20, 20)]); $drawable->setBackgroundColor('b53717'); $image->modify(new DrawPolygonModifier($drawable)); $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/CoverDownModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/CoverDownModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\CoverDownModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\CoverModifier::class)] final class CoverDownModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new CoverDownModifier(100, 100, 'center')); $this->assertEquals(100, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); $this->assertTransparency($image->pickColor(90, 30)); } public function testModifyOddSize(): void { $image = $this->createTestImage(375, 250); $image->modify(new CoverDownModifier(240, 90, 'center')); $this->assertEquals(240, $image->width()); $this->assertEquals(90, $image->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/PixelateModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/PixelateModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\PixelateModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\PixelateModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\PixelateModifier::class)] final class PixelateModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new PixelateModifier(10)); [$r, $g, $b] = $image->pickColor(0, 0)->toArray(); $this->assertEquals(0, $r); $this->assertEquals(174, $g); $this->assertEquals(240, $b); [$r, $g, $b] = $image->pickColor(14, 14)->toArray(); $this->assertEquals(107, $r); $this->assertEquals(171, $g); $this->assertEquals(140, $b); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/DrawBezierModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/DrawBezierModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawBezierModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Bezier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\DrawBezierModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawBezierModifier::class)] final class DrawBezierModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $drawable = new Bezier([ new Point(0, 0), new Point(15, 0), new Point(15, 15), new Point(0, 15) ]); $drawable->setBackgroundColor('b53717'); $image->modify(new DrawBezierModifier($drawable)); $this->assertEquals('b53717', $image->pickColor(5, 5)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\BlurModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\BlurModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\BlurModifier::class)] final class BlurModifierTest extends ImagickTestCase { public function testColorChange(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new BlurModifier(30)); $this->assertEquals('42acb2', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResizeModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ResizeModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResizeModifier::class)] final class ResizeModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new ResizeModifier(200, 100)); $this->assertEquals(200, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(150, 70)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResizeCanvasModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ResizeCanvasModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ResizeCanvasModifier::class)] final class ResizeCanvasModifierTest extends ImagickTestCase { public function testModify(): void { $image = $this->createTestImage(1, 1); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new ResizeCanvasModifier(3, 3, 'ff0', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); } public function testModifyWithTransparency(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $image->modify(new ResizeCanvasModifier(18, 18, 'ff0', 'center')); $this->assertEquals(18, $image->width()); $this->assertEquals(18, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); $this->assertTransparency($image->pickColor(12, 1)); $image = $this->createTestImage(16, 16); $image->modify(new ResizeCanvasModifier(32, 32, '00f5', 'center')); $this->assertEquals(32, $image->width()); $this->assertEquals(32, $image->height()); $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 5)); $this->assertColor(0, 0, 255, 77, $image->pickColor(16, 5)); $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 5)); $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 16)); $this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16)); $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 16)); $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 30)); $this->assertColor(0, 0, 255, 77, $image->pickColor(16, 30)); $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 30)); } public function testModifyEdge(): void { $image = $this->createTestImage(1, 1); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom')); $this->assertEquals(1, $image->width()); $this->assertEquals(2, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 1)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/DrawEllipseModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/DrawEllipseModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawEllipseModifier; use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\DrawEllipseModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\DrawEllipseModifier::class)] final class DrawEllipseModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $drawable = new Ellipse(10, 10, new Point(14, 14)); $drawable->setBackgroundColor('b53717'); $image->modify(new DrawEllipseModifier($drawable)); $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Modifiers\FillModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\FillModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\FillModifier::class)] final class FillModifierTest extends ImagickTestCase { public function testFloodFillColor(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); $image->modify(new FillModifier(new Color(204, 204, 204), new Point(540, 400))); $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); } public function testFillAllColor(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); $image->modify(new FillModifier(new Color(204, 204, 204))); $this->assertEquals('cccccc', $image->pickColor(420, 270)->toHex()); $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/ContrastModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/ContrastModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ContrastModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\ContrastModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\ContrastModifier::class)] final class ContrastModifierTest extends ImagickTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new ContrastModifier(30)); $this->assertEquals('00fcff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/GreyscaleModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/GreyscaleModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\GreyscaleModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\GreyscaleModifier::class)] final class GreyscaleModifierTest extends ImagickTestCase { public function testColorChange(): void { $image = $this->readTestImage('trim.png'); $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); $image->modify(new GreyscaleModifier()); $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\PlaceModifier; use Intervention\Image\Tests\ImagickTestCase; use Intervention\Image\Drivers\Imagick\Modifiers\PlaceModifier as PlaceModifierImagick; #[RequiresPhpExtension('imagick')] #[CoversClass(PlaceModifier::class)] #[CoversClass(PlaceModifierImagick::class)] final class PlaceModifierTest extends ImagickTestCase { public function testColorChange(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0)); $this->assertEquals('33260e', $image->pickColor(300, 25)->toHex()); } public function testColorChangeOpacityPng(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0, 50)); $this->assertColor(152, 112, 40, 255, $image->pickColor(300, 25), tolerance: 1); $this->assertColor(255, 202, 107, 255, $image->pickColor(274, 5), tolerance: 1); } public function testColorChangeOpacityJpeg(): void { $image = $this->createTestImage(16, 16)->fill('0000ff'); $this->assertEquals('0000ff', $image->pickColor(10, 10)->toHex()); $image->modify(new PlaceModifier($this->getTestResourcePath('exif.jpg'), opacity: 50)); $this->assertColor(127, 83, 127, 255, $image->pickColor(10, 10), tolerance: 1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/TrimModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/TrimModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use Intervention\Image\Exceptions\NotSupportedException; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\TrimModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\TrimModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\TrimModifier::class)] final class TrimModifierTest extends ImagickTestCase { public function testTrim(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals(50, $image->width()); $this->assertEquals(50, $image->height()); $image->modify(new TrimModifier()); $this->assertEquals(28, $image->width()); $this->assertEquals(28, $image->height()); } public function testTrimGradient(): void { $image = $this->readTestImage('radial.png'); $this->assertEquals(50, $image->width()); $this->assertEquals(50, $image->height()); $image->modify(new TrimModifier(50)); $this->assertEquals(29, $image->width()); $this->assertEquals(29, $image->height()); } public function testTrimHighTolerance(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals(50, $image->width()); $this->assertEquals(50, $image->height()); $image->modify(new TrimModifier(1000000)); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $this->assertColor(255, 255, 255, 0, $image->pickColor(0, 0)); } public function testTrimAnimated(): void { $image = $this->readTestImage('animation.gif'); $this->expectException(NotSupportedException::class); $image->modify(new TrimModifier()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\RotateModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\RotateModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\RotateModifier::class)] final class RotateModifierTest extends ImagickTestCase { public function testRotate(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals(320, $image->width()); $this->assertEquals(240, $image->height()); $image->modify(new RotateModifier(90, 'fff')); $this->assertEquals(240, $image->width()); $this->assertEquals(320, $image->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\GammaModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\GammaModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\GammaModifier::class)] final class GammaModifierTest extends ImagickTestCase { public function testModifier(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $image->modify(new GammaModifier(2.1)); $this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php
tests/Unit/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\FlipModifier; use Intervention\Image\Modifiers\FlopModifier; use Intervention\Image\Tests\ImagickTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(\Intervention\Image\Modifiers\FlipModifier::class)] #[CoversClass(\Intervention\Image\Modifiers\FlopModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\FlipModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\FlopModifier::class)] final class FlipFlopModifierTest extends ImagickTestCase { public function testFlipImage(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); $image->modify(new FlipModifier()); $this->assertEquals('00000000', $image->pickColor(0, 0)->toHex()); } public function testFlopImage(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); $image->modify(new FlopModifier()); $this->assertEquals('00000000', $image->pickColor(0, 0)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/PolygonTest.php
tests/Unit/Geometry/PolygonTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Polygon; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Polygon::class)] final class PolygonTest extends BaseTestCase { public function testConstructor(): void { $poly = new Polygon([]); $this->assertInstanceOf(Polygon::class, $poly); $this->assertEquals(0, $poly->count()); } public function testCount(): void { $poly = new Polygon([new Point(), new Point()]); $this->assertEquals(2, $poly->count()); } public function testArrayAccess(): void { $poly = new Polygon([new Point(), new Point()]); $this->assertInstanceOf(Point::class, $poly[0]); $this->assertInstanceOf(Point::class, $poly[1]); } public function testAddPoint(): void { $poly = new Polygon([new Point(), new Point()]); $this->assertEquals(2, $poly->count()); $result = $poly->addPoint(new Point()); $this->assertEquals(3, $poly->count()); $this->assertInstanceOf(Polygon::class, $result); } public function testGetCenterPoint(): void { $poly = new Polygon([ new Point(0, 0), new Point(20, 0), new Point(20, -20), new Point(0, -20), ]); $result = $poly->centerPoint(); $this->assertEquals(10, $result->x()); $this->assertEquals(-10, $result->y()); $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(0, 0)); $result = $poly->centerPoint(); $this->assertEquals(150, $result->x()); $this->assertEquals(-100, $result->y()); } public function testGetWidth(): void { $poly = new Polygon([ new Point(12, 45), new Point(-23, -49), new Point(3, 566), ]); $this->assertEquals($poly->width(), 35); } public function testGetHeight(): void { $poly = new Polygon([ new Point(12, 45), new Point(-23, -49), new Point(3, 566), ]); $this->assertEquals(615, $poly->height()); $poly = new Polygon([ new Point(250, 207), new Point(473, 207), new Point(473, 250), new Point(250, 250), ], new Point(250, 250)); $this->assertEquals(43, $poly->height()); } public function testFirst(): void { $poly = new Polygon([ new Point(12, 45), new Point(-23, -49), new Point(3, 566), ]); $this->assertEquals(12, $poly->first()->x()); $this->assertEquals(45, $poly->first()->y()); } public function testFirstEmpty(): void { $poly = new Polygon(); $this->assertNull($poly->first()); } public function testLast(): void { $poly = new Polygon([ new Point(12, 45), new Point(-23, -49), new Point(3, 566), ]); $this->assertEquals(3, $poly->last()->x()); $this->assertEquals(566, $poly->last()->y()); } public function testLastEmpty(): void { $poly = new Polygon(); $this->assertNull($poly->last()); } public function testOffsetExists(): void { $poly = new Polygon(); $this->assertFalse($poly->offsetExists(0)); $this->assertFalse($poly->offsetExists(1)); $poly->addPoint(new Point(0, 0)); $this->assertTrue($poly->offsetExists(0)); $this->assertFalse($poly->offsetExists(1)); } public function testOffsetSetUnset(): void { $poly = new Polygon(); $poly->offsetSet(0, new Point()); $poly->offsetSet(2, new Point()); $this->assertTrue($poly->offsetExists(0)); $this->assertFalse($poly->offsetExists(1)); $this->assertTrue($poly->offsetExists(2)); $poly->offsetUnset(2); $this->assertTrue($poly->offsetExists(0)); $this->assertFalse($poly->offsetExists(1)); $this->assertFalse($poly->offsetExists(2)); } public function testGetSetPivotPoint(): void { $poly = new Polygon(); $this->assertInstanceOf(Point::class, $poly->pivot()); $this->assertEquals(0, $poly->pivot()->x()); $this->assertEquals(0, $poly->pivot()->y()); $result = $poly->setPivot(new Point(12, 34)); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(12, $poly->pivot()->x()); $this->assertEquals(34, $poly->pivot()->y()); } public function testGetMostLeftPoint(): void { $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(-32, -200), ], new Point(0, 0)); $result = $poly->mostLeftPoint(); $this->assertEquals(-32, $result->x()); $this->assertEquals(-200, $result->y()); } public function testGetMostRightPoint(): void { $poly = new Polygon([ new Point(0, 0), new Point(350, 0), new Point(300, -200), new Point(-32, -200), ], new Point(0, 0)); $result = $poly->mostRightPoint(); $this->assertEquals(350, $result->x()); $this->assertEquals(0, $result->y()); } public function testGetMostTopPoint(): void { $poly = new Polygon([ new Point(0, 100), new Point(350, 0), new Point(300, -200), new Point(-32, 200), ], new Point(0, 0)); $result = $poly->mostTopPoint(); $this->assertEquals(-32, $result->x()); $this->assertEquals(200, $result->y()); } public function testGetMostBottomPoint(): void { $poly = new Polygon([ new Point(0, 100), new Point(350, 0), new Point(300, -200), new Point(-32, 200), ], new Point(0, 0)); $result = $poly->mostBottomPoint(); $this->assertEquals(300, $result->x()); $this->assertEquals(-200, $result->y()); } public function testAlignCenter(): void { $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(0, 0)); $result = $poly->align('center'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-150, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(150, $result[1]->x()); $this->assertEquals(0, $result[1]->y()); $this->assertEquals(150, $result[2]->x()); $this->assertEquals(-200, $result[2]->y()); $this->assertEquals(-150, $result[3]->x()); $this->assertEquals(-200, $result[3]->y()); $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(-1000, -1000)); $result = $poly->align('center'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-1150, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(-850, $result[1]->x()); $this->assertEquals(0, $result[1]->y()); $this->assertEquals(-850, $result[2]->x()); $this->assertEquals(-200, $result[2]->y()); $this->assertEquals(-1150, $result[3]->x()); $this->assertEquals(-200, $result[3]->y()); } public function testAlignLeft(): void { $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(100, 100)); $result = $poly->align('left'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(100, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(400, $result[1]->x()); $this->assertEquals(0, $result[1]->y()); $this->assertEquals(400, $result[2]->x()); $this->assertEquals(-200, $result[2]->y()); $this->assertEquals(100, $result[3]->x()); $this->assertEquals(-200, $result[3]->y()); $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(-1000, -1000)); $result = $poly->align('left'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-1000, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(-700, $result[1]->x()); $this->assertEquals(0, $result[1]->y()); $this->assertEquals(-700, $result[2]->x()); $this->assertEquals(-200, $result[2]->y()); $this->assertEquals(-1000, $result[3]->x()); $this->assertEquals(-200, $result[3]->y()); } public function testAlignRight(): void { $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(100, 100)); $result = $poly->align('right'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-200, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(100, $result[1]->x()); $this->assertEquals(0, $result[1]->y()); $this->assertEquals(100, $result[2]->x()); $this->assertEquals(-200, $result[2]->y()); $this->assertEquals(-200, $result[3]->x()); $this->assertEquals(-200, $result[3]->y()); $poly = new Polygon([ new Point(0, 0), new Point(300, 0), new Point(300, -200), new Point(0, -200), ], new Point(-1000, -1000)); $result = $poly->align('right'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-1300, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(-1000, $result[1]->x()); $this->assertEquals(0, $result[1]->y()); $this->assertEquals(-1000, $result[2]->x()); $this->assertEquals(-200, $result[2]->y()); $this->assertEquals(-1300, $result[3]->x()); $this->assertEquals(-200, $result[3]->y()); } public function testValignMiddle(): void { $poly = new Polygon([ new Point(-21, -22), new Point(91, -135), new Point(113, -113), new Point(0, 0), ], new Point(250, 250)); $result = $poly->valign('middle'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-21, $result[0]->x()); $this->assertEquals(296, $result[0]->y()); $this->assertEquals(91, $result[1]->x()); $this->assertEquals(183, $result[1]->y()); $this->assertEquals(113, $result[2]->x()); $this->assertEquals(205, $result[2]->y()); $this->assertEquals(0, $result[3]->x()); $this->assertEquals(318, $result[3]->y()); } public function testValignTop(): void { $poly = new Polygon([ new Point(-21, -22), new Point(91, -135), new Point(113, -113), new Point(0, 0), ], new Point(250, 250)); $result = $poly->valign('top'); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(-21, $result[0]->x()); $this->assertEquals(363, $result[0]->y()); $this->assertEquals(91, $result[1]->x()); $this->assertEquals(250, $result[1]->y()); $this->assertEquals(113, $result[2]->x()); $this->assertEquals(272, $result[2]->y()); $this->assertEquals(0, $result[3]->x()); $this->assertEquals(385, $result[3]->y()); } public function testMovePoints(): void { $poly = new Polygon([ new Point(10, 20), new Point(30, 40) ]); $result = $poly->movePointsX(100); $this->assertEquals(110, $result[0]->x()); $this->assertEquals(20, $result[0]->y()); $this->assertEquals(130, $result[1]->x()); $this->assertEquals(40, $result[1]->y()); $result = $poly->movePointsY(200); $this->assertEquals(110, $result[0]->x()); $this->assertEquals(220, $result[0]->y()); $this->assertEquals(130, $result[1]->x()); $this->assertEquals(240, $result[1]->y()); } public function testRotate(): void { $poly = new Polygon([ new Point(0, 0), new Point(50, 0), new Point(50, -50), new Point(0, -50), ]); $result = $poly->rotate(45); $this->assertInstanceOf(Polygon::class, $result); $this->assertEquals(0, $result[0]->x()); $this->assertEquals(0, $result[0]->y()); $this->assertEquals(35, $result[1]->x()); $this->assertEquals(35, $result[1]->y()); $this->assertEquals(70, $result[2]->x()); $this->assertEquals(0, $result[2]->y()); $this->assertEquals(35, $result[3]->x()); $this->assertEquals(-35, $result[3]->y()); } public function testToArray(): void { $poly = new Polygon([ new Point(0, 0), new Point(50, 0), new Point(50, -50), new Point(0, -50), ]); $this->assertEquals([0, 0, 50, 0, 50, -50, 0, -50], $poly->toArray()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/EllipseTest.php
tests/Unit/Geometry/EllipseTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Ellipse::class)] final class EllipseTest extends BaseTestCase { public function testConstructor(): void { $ellipse = new Ellipse(10, 20, new Point(100, 200)); $this->assertInstanceOf(Ellipse::class, $ellipse); $this->assertEquals(10, $ellipse->width()); $this->assertEquals(20, $ellipse->height()); } public function testPosition(): void { $ellipse = new Ellipse(10, 20, new Point(100, 200)); $this->assertInstanceOf(Point::class, $ellipse->position()); $this->assertEquals(100, $ellipse->position()->x()); $this->assertEquals(200, $ellipse->position()->y()); $this->assertInstanceOf(Point::class, $ellipse->pivot()); $this->assertEquals(100, $ellipse->pivot()->x()); $this->assertEquals(200, $ellipse->pivot()->y()); } public function testSetSize(): void { $ellipse = new Ellipse(10, 20, new Point(100, 200)); $this->assertEquals(10, $ellipse->width()); $this->assertEquals(20, $ellipse->height()); $result = $ellipse->setSize(100, 200); $this->assertInstanceOf(Ellipse::class, $result); $this->assertEquals(100, $ellipse->width()); $this->assertEquals(200, $ellipse->height()); } public function testSetWidthHeight(): void { $ellipse = new Ellipse(10, 20, new Point(100, 200)); $this->assertEquals(10, $ellipse->width()); $this->assertEquals(20, $ellipse->height()); $result = $ellipse->setWidth(100); $this->assertInstanceOf(Ellipse::class, $result); $this->assertEquals(100, $ellipse->width()); $this->assertEquals(20, $ellipse->height()); $result = $ellipse->setHeight(200); $this->assertInstanceOf(Ellipse::class, $result); $this->assertEquals(100, $ellipse->width()); $this->assertEquals(200, $ellipse->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/CircleTest.php
tests/Unit/Geometry/CircleTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use Intervention\Image\Geometry\Circle; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Circle::class)] final class CircleTest extends BaseTestCase { public function testConstructor(): void { $circle = new Circle(100, new Point(1, 2)); $this->assertInstanceOf(Circle::class, $circle); $this->assertEquals(100, $circle->diameter()); $this->assertInstanceOf(Point::class, $circle->pivot()); } public function testSetGetDiameter(): void { $circle = new Circle(100, new Point(1, 2)); $this->assertEquals(100, $circle->diameter()); $result = $circle->setDiameter(200); $this->assertInstanceOf(Circle::class, $result); $this->assertEquals(200, $result->diameter()); $this->assertEquals(200, $circle->diameter()); } public function testSetGetRadius(): void { $circle = new Circle(100, new Point(1, 2)); $this->assertEquals(50, $circle->radius()); $result = $circle->setRadius(200); $this->assertInstanceOf(Circle::class, $result); $this->assertEquals(400, $result->diameter()); $this->assertEquals(400, $circle->diameter()); $this->assertEquals(200, $result->radius()); $this->assertEquals(200, $circle->radius()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/RectangleTest.php
tests/Unit/Geometry/RectangleTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\PointInterface; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Rectangle::class)] final class RectangleTest extends BaseTestCase { public function testConstructor(): void { $rectangle = new Rectangle(300, 200); $this->assertEquals(0, $rectangle[0]->x()); $this->assertEquals(0, $rectangle[0]->y()); $this->assertEquals(300, $rectangle[1]->x()); $this->assertEquals(0, $rectangle[1]->y()); $this->assertEquals(300, $rectangle[2]->x()); $this->assertEquals(-200, $rectangle[2]->y()); $this->assertEquals(0, $rectangle[3]->x()); $this->assertEquals(-200, $rectangle[3]->y()); $this->assertEquals(300, $rectangle->width()); $this->assertEquals(200, $rectangle->height()); } public function testSetSize(): void { $rectangle = new Rectangle(300, 200); $rectangle->setSize(12, 34); $this->assertEquals(12, $rectangle->width()); $this->assertEquals(34, $rectangle->height()); } public function testSetWidth(): void { $rectangle = new Rectangle(300, 200); $this->assertEquals(300, $rectangle->width()); $rectangle->setWidth(400); $this->assertEquals(400, $rectangle->width()); } public function testSetHeight(): void { $rectangle = new Rectangle(300, 200); $this->assertEquals(200, $rectangle->height()); $rectangle->setHeight(800); $this->assertEquals(800, $rectangle->height()); } public function testGetAspectRatio(): void { $size = new Rectangle(800, 600); $this->assertEquals(1.333, round($size->aspectRatio(), 3)); $size = new Rectangle(100, 100); $this->assertEquals(1, $size->aspectRatio()); $size = new Rectangle(1920, 1080); $this->assertEquals(1.778, round($size->aspectRatio(), 3)); } public function testFitsInto(): void { $box = new Rectangle(800, 600); $fits = $box->fitsInto(new Rectangle(100, 100)); $this->assertFalse($fits); $box = new Rectangle(800, 600); $fits = $box->fitsInto(new Rectangle(1000, 100)); $this->assertFalse($fits); $box = new Rectangle(800, 600); $fits = $box->fitsInto(new Rectangle(100, 1000)); $this->assertFalse($fits); $box = new Rectangle(800, 600); $fits = $box->fitsInto(new Rectangle(800, 600)); $this->assertTrue($fits); $box = new Rectangle(800, 600); $fits = $box->fitsInto(new Rectangle(1000, 1000)); $this->assertTrue($fits); $box = new Rectangle(100, 100); $fits = $box->fitsInto(new Rectangle(800, 600)); $this->assertTrue($fits); $box = new Rectangle(100, 100); $fits = $box->fitsInto(new Rectangle(80, 60)); $this->assertFalse($fits); } public function testIsLandscape(): void { $box = new Rectangle(100, 100); $this->assertFalse($box->isLandscape()); $box = new Rectangle(100, 200); $this->assertFalse($box->isLandscape()); $box = new Rectangle(300, 200); $this->assertTrue($box->isLandscape()); } public function testIsPortrait(): void { $box = new Rectangle(100, 100); $this->assertFalse($box->isPortrait()); $box = new Rectangle(200, 100); $this->assertFalse($box->isPortrait()); $box = new Rectangle(200, 300); $this->assertTrue($box->isPortrait()); } public function testSetGetPivot(): void { $box = new Rectangle(800, 600); $pivot = $box->pivot(); $this->assertInstanceOf(Point::class, $pivot); $this->assertEquals(0, $pivot->x()); $result = $box->setPivot(new Point(10, 0)); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(10, $box->pivot()->x()); } public function testAlignPivot(): void { $box = new Rectangle(640, 480); $this->assertEquals(0, $box->pivot()->x()); $this->assertEquals(0, $box->pivot()->y()); $box->movePivot('top-left', 3, 3); $this->assertEquals(3, $box->pivot()->x()); $this->assertEquals(3, $box->pivot()->y()); $box->movePivot('top', 3, 3); $this->assertEquals(323, $box->pivot()->x()); $this->assertEquals(3, $box->pivot()->y()); $box->movePivot('top-right', 3, 3); $this->assertEquals(637, $box->pivot()->x()); $this->assertEquals(3, $box->pivot()->y()); $box->movePivot('left', 3, 3); $this->assertEquals(3, $box->pivot()->x()); $this->assertEquals(243, $box->pivot()->y()); $box->movePivot('center', 3, 3); $this->assertEquals(323, $box->pivot()->x()); $this->assertEquals(243, $box->pivot()->y()); $box->movePivot('right', 3, 3); $this->assertEquals(637, $box->pivot()->x()); $this->assertEquals(243, $box->pivot()->y()); $box->movePivot('bottom-left', 3, 3); $this->assertEquals(3, $box->pivot()->x()); $this->assertEquals(477, $box->pivot()->y()); $box->movePivot('bottom', 3, 3); $this->assertEquals(323, $box->pivot()->x()); $this->assertEquals(477, $box->pivot()->y()); $result = $box->movePivot('bottom-right', 3, 3); $this->assertEquals(637, $box->pivot()->x()); $this->assertEquals(477, $box->pivot()->y()); $this->assertInstanceOf(Rectangle::class, $result); } public function testAlignPivotTo(): void { $container = new Rectangle(800, 600); $size = new Rectangle(200, 100); $size->alignPivotTo($container, 'center'); $this->assertEquals(300, $size->pivot()->x()); $this->assertEquals(250, $size->pivot()->y()); $container = new Rectangle(800, 600); $size = new Rectangle(100, 100); $size->alignPivotTo($container, 'center'); $this->assertEquals(350, $size->pivot()->x()); $this->assertEquals(250, $size->pivot()->y()); $container = new Rectangle(800, 600); $size = new Rectangle(800, 600); $size->alignPivotTo($container, 'center'); $this->assertEquals(0, $size->pivot()->x()); $this->assertEquals(0, $size->pivot()->y()); $container = new Rectangle(100, 100); $size = new Rectangle(800, 600); $size->alignPivotTo($container, 'center'); $this->assertEquals(-350, $size->pivot()->x()); $this->assertEquals(-250, $size->pivot()->y()); $container = new Rectangle(100, 100); $size = new Rectangle(800, 600); $size->alignPivotTo($container, 'bottom-right'); $this->assertEquals(-700, $size->pivot()->x()); $this->assertEquals(-500, $size->pivot()->y()); } public function testgetRelativePositionTo(): void { $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); $container->movePivot('top-left'); $input->movePivot('top-left'); $pos = $container->relativePositionTo($input); $this->assertEquals(0, $pos->x()); $this->assertEquals(0, $pos->y()); $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); $container->movePivot('center'); $input->movePivot('top-left'); $pos = $container->relativePositionTo($input); $this->assertEquals(400, $pos->x()); $this->assertEquals(300, $pos->y()); $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); $container->movePivot('bottom-right'); $input->movePivot('top-right'); $pos = $container->relativePositionTo($input); $this->assertEquals(600, $pos->x()); $this->assertEquals(600, $pos->y()); $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); $container->movePivot('center'); $input->movePivot('center'); $pos = $container->relativePositionTo($input); $this->assertEquals(300, $pos->x()); $this->assertEquals(250, $pos->y()); $container = new Rectangle(100, 200); $input = new Rectangle(100, 100); $container->movePivot('center'); $input->movePivot('center'); $pos = $container->relativePositionTo($input); $this->assertEquals(0, $pos->x()); $this->assertEquals(50, $pos->y()); } public function testTopLeftPoint(): void { $rectangle = new Rectangle(800, 600); $this->assertInstanceOf(PointInterface::class, $rectangle->topLeftPoint()); } public function testBottomRightPoint(): void { $rectangle = new Rectangle(800, 600); $this->assertInstanceOf(PointInterface::class, $rectangle->bottomRightPoint()); } public function testResize(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->resize(300, 200); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(300, $result->width()); $this->assertEquals(200, $result->height()); } public function testResizeDown(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->resizeDown(3000, 200); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(800, $result->width()); $this->assertEquals(200, $result->height()); } public function testScale(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->scale(height: 1200); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(800 * 2, $result->width()); $this->assertEquals(600 * 2, $result->height()); } public function testScaleDown(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->scaleDown(height: 1200); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(800, $result->width()); $this->assertEquals(600, $result->height()); } public function testCover(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->cover(400, 100); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(400, $result->width()); $this->assertEquals(300, $result->height()); } public function testContain(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->contain(1600, 1200); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(1600, $result->width()); $this->assertEquals(1200, $result->height()); } public function testContainMax(): void { $rectangle = new Rectangle(800, 600); $result = $rectangle->containMax(1600, 1200); $this->assertInstanceOf(Rectangle::class, $result); $this->assertEquals(800, $result->width()); $this->assertEquals(600, $result->height()); } public function testDebugInfo(): void { $info = (new Rectangle(800, 600))->__debugInfo(); $this->assertEquals(800, $info['width']); $this->assertEquals(600, $info['height']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/PointTest.php
tests/Unit/Geometry/PointTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Point::class)] final class PointTest extends BaseTestCase { public function testConstructor(): void { $point = new Point(); $this->assertInstanceOf(Point::class, $point); $this->assertEquals(0, $point->x()); $this->assertEquals(0, $point->y()); } public function testConstructorWithParameters(): void { $point = new Point(40, 50); $this->assertInstanceOf(Point::class, $point); $this->assertEquals(40, $point->x()); $this->assertEquals(50, $point->y()); } public function testIteration(): void { $point = new Point(40, 50); foreach ($point as $value) { $this->assertIsInt($value); } } public function testGetSetX(): void { $point = new Point(0, 0); $point->setX(100); $this->assertEquals(100, $point->x()); $this->assertEquals(0, $point->y()); } public function testGetSetY(): void { $point = new Point(0, 0); $point->setY(100); $this->assertEquals(0, $point->x()); $this->assertEquals(100, $point->y()); } public function testmoveX(): void { $point = new Point(50, 50); $point->moveX(100); $this->assertEquals(150, $point->x()); $this->assertEquals(50, $point->y()); } public function testmoveY(): void { $point = new Point(50, 50); $point->moveY(100); $this->assertEquals(50, $point->x()); $this->assertEquals(150, $point->y()); } public function testSetPosition(): void { $point = new Point(0, 0); $point->setPosition(100, 200); $this->assertEquals(100, $point->x()); $this->assertEquals(200, $point->y()); } public function testRotate(): void { $point = new Point(30, 0); $point->rotate(90, new Point(0, 0)); $this->assertEquals(0, $point->x()); $this->assertEquals(30, $point->y()); $point->rotate(90, new Point(0, 0)); $this->assertEquals(-30, $point->x()); $this->assertEquals(0, $point->y()); $point = new Point(300, 200); $point->rotate(90, new Point(0, 0)); $this->assertEquals(-200, $point->x()); $this->assertEquals(300, $point->y()); $point = new Point(0, 74); $point->rotate(45, new Point(0, 0)); $this->assertEquals(-52, $point->x()); $this->assertEquals(52, $point->y()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/LineTest.php
tests/Unit/Geometry/LineTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use Intervention\Image\Geometry\Line; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Line::class)] final class LineTest extends BaseTestCase { public function testConstructor(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertInstanceOf(Line::class, $line); } public function testPosition(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertEquals(1, $line->position()->x()); $this->assertEquals(2, $line->position()->y()); } public function testSetGetStart(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertEquals(1, $line->start()->x()); $this->assertEquals(2, $line->start()->y()); $result = $line->setStart(new Point(10, 20)); $this->assertInstanceOf(Line::class, $result); $this->assertEquals(10, $line->start()->x()); $this->assertEquals(20, $line->start()->y()); } public function testSetGetEnd(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertEquals(3, $line->end()->x()); $this->assertEquals(4, $line->end()->y()); $result = $line->setEnd(new Point(30, 40)); $this->assertInstanceOf(Line::class, $result); $this->assertEquals(30, $line->end()->x()); $this->assertEquals(40, $line->end()->y()); } public function setFrom(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertEquals(1, $line->start()->x()); $this->assertEquals(2, $line->start()->y()); $result = $line->from(10, 20); $this->assertInstanceOf(Line::class, $result); $this->assertEquals(10, $line->start()->x()); $this->assertEquals(20, $line->start()->y()); } public function setTo(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertEquals(3, $line->end()->x()); $this->assertEquals(4, $line->end()->y()); $result = $line->to(30, 40); $this->assertInstanceOf(Line::class, $result); $this->assertEquals(30, $line->end()->x()); $this->assertEquals(40, $line->end()->y()); } public function testSetGetWidth(): void { $line = new Line(new Point(1, 2), new Point(3, 4), 10); $this->assertEquals(10, $line->width()); $result = $line->setWidth(20); $this->assertInstanceOf(Line::class, $result); $this->assertEquals(20, $line->width()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/RectangleResizerTest.php
tests/Unit/Geometry/RectangleResizerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Geometry\Tools\RectangleResizer; use PHPUnit\Framework\TestCase; #[CoversClass(RectangleResizer::class)] final class RectangleResizerTest extends TestCase { public function testMake(): void { $resizer = RectangleResizer::to(); $this->assertInstanceOf(RectangleResizer::class, $resizer); $resizer = RectangleResizer::to(height: 100); $this->assertInstanceOf(RectangleResizer::class, $resizer); $resizer = RectangleResizer::to(100); $this->assertInstanceOf(RectangleResizer::class, $resizer); $resizer = RectangleResizer::to(100, 100); $this->assertInstanceOf(RectangleResizer::class, $resizer); } public function testToWidth(): void { $resizer = new RectangleResizer(); $result = $resizer->toWidth(100); $this->assertInstanceOf(RectangleResizer::class, $result); } public function testToHeight(): void { $resizer = new RectangleResizer(); $result = $resizer->toHeight(100); $this->assertInstanceOf(RectangleResizer::class, $result); } public function testToSize(): void { $resizer = new RectangleResizer(); $resizer = $resizer->toSize(new Rectangle(200, 100)); $this->assertInstanceOf(RectangleResizer::class, $resizer); } /** * @param $resizeParameters array<string, int> */ #[DataProvider('resizeDataProvider')] public function testResize(Rectangle $input, array $resizeParameters, Rectangle $result): void { $resizer = new RectangleResizer(...$resizeParameters); $resized = $resizer->resize($input); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); } public static function resizeDataProvider(): Generator { yield [new Rectangle(300, 200), ['width' => 150], new Rectangle(150, 200)]; yield [new Rectangle(300, 200), ['height' => 150], new Rectangle(300, 150)]; yield [new Rectangle(300, 200), ['width' => 20, 'height' => 10], new Rectangle(20, 10)]; yield [new Rectangle(300, 200), [], new Rectangle(300, 200)]; } /** * @param $resizeParameters array<string, int> */ #[DataProvider('resizeDownDataProvider')] public function testResizeDown(Rectangle $input, array $resizeParameters, Rectangle $result): void { $resizer = new RectangleResizer(...$resizeParameters); $resized = $resizer->resizeDown($input); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); } public static function resizeDownDataProvider(): Generator { yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 2000], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), ['width' => 400, 'height' => 1000], new Rectangle(400, 600)]; yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 400], new Rectangle(800, 400)]; yield [new Rectangle(800, 600), ['width' => 400, 'height' => 300], new Rectangle(400, 300)]; yield [new Rectangle(800, 600), ['width' => 1000], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), ['height' => 1000], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), [], new Rectangle(800, 600)]; } /** * @param $resizeParameters array<string, int> */ #[DataProvider('scaleDataProvider')] public function testScale(Rectangle $input, array $resizeParameters, Rectangle $result): void { $resizer = new RectangleResizer(...$resizeParameters); $resized = $resizer->scale($input); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); } public static function scaleDataProvider(): Generator { yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 2000], new Rectangle(1000, 750)]; yield [new Rectangle(800, 600), ['width' => 2000, 'height' => 1000], new Rectangle(1333, 1000)]; yield [new Rectangle(800, 600), ['height' => 3000], new Rectangle(4000, 3000)]; yield [new Rectangle(800, 600), ['width' => 8000], new Rectangle(8000, 6000)]; yield [new Rectangle(800, 600), ['width' => 100, 'height' => 400], new Rectangle(100, 75)]; yield [new Rectangle(800, 600), ['width' => 400, 'height' => 100], new Rectangle(133, 100)]; yield [new Rectangle(800, 600), ['height' => 300], new Rectangle(400, 300)]; yield [new Rectangle(800, 600), ['width' => 80], new Rectangle(80, 60)]; yield [new Rectangle(640, 480), ['width' => 225], new Rectangle(225, 169)]; yield [new Rectangle(640, 480), ['width' => 223], new Rectangle(223, 167)]; yield [new Rectangle(600, 800), ['width' => 300, 'height' => 300], new Rectangle(225, 300)]; yield [new Rectangle(800, 600), ['width' => 400, 'height' => 10], new Rectangle(13, 10)]; yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 1200], new Rectangle(1000, 750)]; yield [new Rectangle(12000, 12), ['width' => 4000, 'height' => 3000], new Rectangle(4000, 4)]; yield [new Rectangle(12, 12000), ['width' => 4000, 'height' => 3000], new Rectangle(3, 3000)]; yield [new Rectangle(12000, 6000), ['width' => 4000, 'height' => 3000], new Rectangle(4000, 2000)]; yield [new Rectangle(3, 3000), ['height' => 300], new Rectangle(1, 300)]; yield [new Rectangle(800, 600), [], new Rectangle(800, 600)]; } /** * @param $resizeParameters array<string, int> */ #[DataProvider('scaleDownDataProvider')] public function testScaleDown(Rectangle $input, array $resizeParameters, Rectangle $result): void { $resizer = new RectangleResizer(...$resizeParameters); $resized = $resizer->scaleDown($input); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); } public static function scaleDownDataProvider(): Generator { yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 2000], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 600], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), ['width' => 1000, 'height' => 300], new Rectangle(400, 300)]; yield [new Rectangle(800, 600), ['width' => 400, 'height' => 1000], new Rectangle(400, 300)]; yield [new Rectangle(800, 600), ['width' => 400], new Rectangle(400, 300)]; yield [new Rectangle(800, 600), ['height' => 300], new Rectangle(400, 300)]; yield [new Rectangle(800, 600), ['width' => 1000], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), ['height' => 1000], new Rectangle(800, 600)]; yield [new Rectangle(800, 600), ['width' => 100], new Rectangle(100, 75)]; yield [new Rectangle(800, 600), ['width' => 300, 'height' => 200], new Rectangle(267, 200)]; yield [new Rectangle(600, 800), ['width' => 300, 'height' => 300], new Rectangle(225, 300)]; yield [new Rectangle(800, 600), ['width' => 400, 'height' => 10], new Rectangle(13, 10)]; yield [new Rectangle(3, 3000), ['height' => 300], new Rectangle(1, 300)]; yield [new Rectangle(800, 600), [], new Rectangle(800, 600)]; } #[DataProvider('coverDataProvider')] public function testCover(Rectangle $origin, Rectangle $target, Rectangle $result): void { $resizer = new RectangleResizer(); $resizer->toSize($target); $resized = $resizer->cover($origin); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); } public static function coverDataProvider(): Generator { yield [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(133, 100)]; yield [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(200, 150)]; yield [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(267, 200)]; yield [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(2000, 1500)]; yield [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(2667, 2000)]; yield [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)]; yield [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(160, 120)]; yield [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(100, 133)]; yield [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(800, 800)]; } #[DataProvider('containDataProvider')] public function testContain(Rectangle $origin, Rectangle $target, Rectangle $result): void { $resizer = new RectangleResizer(); $resizer->toSize($target); $resized = $resizer->contain($origin); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); } public static function containDataProvider(): Generator { yield [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(100, 75)]; yield [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(133, 100)]; yield [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(100, 75)]; yield [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(13, 10)]; yield [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(10, 8)]; yield [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)]; yield [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(120, 90)]; yield [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(75, 100)]; yield [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(600, 600)]; } #[DataProvider('cropDataProvider')] public function testCrop(Rectangle $origin, Rectangle $target, string $position, Rectangle $result): void { $resizer = new RectangleResizer(); $resizer->toSize($target); $resized = $resizer->crop($origin, $position); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); $this->assertEquals($result->pivot()->x(), $resized->pivot()->x()); $this->assertEquals($result->pivot()->y(), $resized->pivot()->y()); } public static function cropDataProvider(): Generator { yield [ new Rectangle(800, 600), new Rectangle(100, 100), 'center', new Rectangle(100, 100, new Point(350, 250)) ]; yield [ new Rectangle(800, 600), new Rectangle(200, 100), 'center', new Rectangle(200, 100, new Point(300, 250)) ]; yield [ new Rectangle(800, 600), new Rectangle(100, 200), 'center', new Rectangle(100, 200, new Point(350, 200)) ]; yield [ new Rectangle(800, 600), new Rectangle(2000, 10), 'center', new Rectangle(2000, 10, new Point(-600, 295)) ]; yield [ new Rectangle(800, 600), new Rectangle(10, 2000), 'center', new Rectangle(10, 2000, new Point(395, -700)) ]; yield [ new Rectangle(800, 600), new Rectangle(800, 600), 'center', new Rectangle(800, 600, new Point(0, 0)) ]; yield [ new Rectangle(400, 300), new Rectangle(120, 120), 'center', new Rectangle(120, 120, new Point(140, 90)) ]; yield [ new Rectangle(600, 800), new Rectangle(100, 100), 'center', new Rectangle(100, 100, new Point(250, 350)) ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/PixelTest.php
tests/Unit/Geometry/PixelTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use Intervention\Image\Colors\Rgb\Color; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Geometry\Pixel; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Pixel::class)] final class PixelTest extends BaseTestCase { public function testSetGetBackground(): void { $color = new Color(255, 55, 0); $pixel = new Pixel(new Color(0, 0, 0), 10, 12); $result = $pixel->setBackgroundColor($color); $this->assertEquals($color, $pixel->backgroundColor()); $this->assertInstanceOf(Pixel::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/BezierTest.php
tests/Unit/Geometry/BezierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Bezier; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Bezier::class)] final class BezierTest extends BaseTestCase { public function testConstructor(): void { $bezier = new Bezier([]); $this->assertInstanceOf(Bezier::class, $bezier); $this->assertEquals(0, $bezier->count()); } public function testCount(): void { $bezier = new Bezier([ new Point(), new Point(), new Point(), new Point() ]); $this->assertEquals(4, $bezier->count()); } public function testArrayAccess(): void { $bezier = new Bezier([ new Point(), new Point(), new Point(), new Point() ]); $this->assertInstanceOf(Point::class, $bezier[0]); $this->assertInstanceOf(Point::class, $bezier[1]); $this->assertInstanceOf(Point::class, $bezier[2]); $this->assertInstanceOf(Point::class, $bezier[3]); } public function testAddPoint(): void { $bezier = new Bezier([ new Point(), new Point() ]); $this->assertEquals(2, $bezier->count()); $result = $bezier->addPoint(new Point()); $this->assertEquals(3, $bezier->count()); $this->assertInstanceOf(Bezier::class, $result); } public function testFirst(): void { $bezier = new Bezier([ new Point(50, 45), new Point(100, -49), new Point(-100, 100), new Point(200, 300), ]); $this->assertEquals(50, $bezier->first()->x()); $this->assertEquals(45, $bezier->first()->y()); } public function testFirstEmpty(): void { $bezier = new Bezier(); $this->assertNull($bezier->first()); } public function testSecond(): void { $bezier = new Bezier([ new Point(50, 45), new Point(100, -49), new Point(-100, 100), new Point(200, 300), ]); $this->assertEquals(100, $bezier->second()->x()); $this->assertEquals(-49, $bezier->second()->y()); } public function testSecondEmpty(): void { $bezier = new Bezier(); $this->assertNull($bezier->second()); } public function testThird(): void { $bezier = new Bezier([ new Point(50, 45), new Point(100, -49), new Point(-100, 100), new Point(200, 300), ]); $this->assertEquals(-100, $bezier->third()->x()); $this->assertEquals(100, $bezier->third()->y()); } public function testThirdEmpty(): void { $bezier = new Bezier(); $this->assertNull($bezier->third()); } public function testLast(): void { $bezier = new Bezier([ new Point(50, 45), new Point(100, -49), new Point(-100, 100), new Point(200, 300), ]); $this->assertEquals(200, $bezier->last()->x()); $this->assertEquals(300, $bezier->last()->y()); } public function testLastEmpty(): void { $bezier = new Bezier(); $this->assertNull($bezier->last()); } public function testOffsetExists(): void { $bezier = new Bezier(); $this->assertFalse($bezier->offsetExists(0)); $this->assertFalse($bezier->offsetExists(1)); $bezier->addPoint(new Point(0, 0)); $this->assertTrue($bezier->offsetExists(0)); $this->assertFalse($bezier->offsetExists(1)); } public function testOffsetSetUnset(): void { $bezier = new Bezier(); $bezier->offsetSet(0, new Point()); $bezier->offsetSet(2, new Point()); $this->assertTrue($bezier->offsetExists(0)); $this->assertFalse($bezier->offsetExists(1)); $this->assertTrue($bezier->offsetExists(2)); $bezier->offsetUnset(2); $this->assertTrue($bezier->offsetExists(0)); $this->assertFalse($bezier->offsetExists(1)); $this->assertFalse($bezier->offsetExists(2)); } public function testGetSetPivotPoint(): void { $bezier = new Bezier(); $this->assertInstanceOf(Point::class, $bezier->pivot()); $this->assertEquals(0, $bezier->pivot()->x()); $this->assertEquals(0, $bezier->pivot()->y()); $result = $bezier->setPivot(new Point(12, 34)); $this->assertInstanceOf(Bezier::class, $result); $this->assertEquals(12, $bezier->pivot()->x()); $this->assertEquals(34, $bezier->pivot()->y()); } public function testToArray(): void { $bezier = new Bezier([ new Point(50, 50), new Point(100, 50), new Point(-50, -100), new Point(50, 100), ]); $this->assertEquals([50, 50, 100, 50, -50, -100, 50, 100], $bezier->toArray()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Traits/HasBorderTest.php
tests/Unit/Geometry/Traits/HasBorderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Traits; use Intervention\Image\Geometry\Traits\HasBorder; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(HasBorder::class)] final class HasBorderTest extends BaseTestCase { public function getTestObject(): object { return new class () { use HasBorder; }; } public function testSetBorder(): void { $object = $this->getTestObject(); $this->assertNull($object->borderColor()); $this->assertEquals(0, $object->borderSize()); $this->assertFalse($object->hasBorder()); $object->setBorder('fff', 10); $this->assertEquals('fff', $object->borderColor()); $this->assertEquals(10, $object->borderSize()); $this->assertTrue($object->hasBorder()); } public function testSetBorderSize(): void { $object = $this->getTestObject(); $this->assertEquals(0, $object->borderSize()); $object->setBorderSize(10); $this->assertEquals(10, $object->borderSize()); } public function testSetBorderColor(): void { $object = $this->getTestObject(); $this->assertNull($object->borderColor()); $object->setBorderColor('fff'); $this->assertEquals('fff', $object->borderColor()); $this->assertFalse($object->hasBorder()); } public function testHasBorder(): void { $object = $this->getTestObject(); $this->assertFalse($object->hasBorder()); $object->setBorderColor('fff'); $this->assertFalse($object->hasBorder()); $object->setBorderSize(1); $this->assertTrue($object->hasBorder()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Traits/HasBackgroundColorTest.php
tests/Unit/Geometry/Traits/HasBackgroundColorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Traits; use Intervention\Image\Geometry\Traits\HasBackgroundColor; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(HasBackgroundColor::class)] final class HasBackgroundColorTest extends BaseTestCase { public function getTestObject(): object { return new class () { use HasBackgroundColor; }; } public function testSetGetBackgroundColor(): void { $object = $this->getTestObject(); $this->assertNull($object->backgroundColor()); $this->assertFalse($object->hasBackgroundColor()); $object->setBackgroundColor('fff'); $this->assertEquals('fff', $object->backgroundColor()); $this->assertTrue($object->hasBackgroundColor()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/BezierFactoryTest.php
tests/Unit/Geometry/Factories/BezierFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Factories\BezierFactory; use Intervention\Image\Geometry\Bezier; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(BezierFactory::class)] final class BezierFactoryTest extends BaseTestCase { public function testFactoryCallback(): void { $factory = new BezierFactory(function ($bezier): void { $bezier->background('f00'); $bezier->border('ff0', 10); $bezier->point(300, 260); $bezier->point(150, 335); $bezier->point(300, 410); }); $bezier = $factory(); $this->assertInstanceOf(Bezier::class, $bezier); $this->assertTrue($bezier->hasBackgroundColor()); $this->assertEquals('f00', $bezier->backgroundColor()); $this->assertEquals('ff0', $bezier->borderColor()); $this->assertEquals(10, $bezier->borderSize()); $this->assertEquals(3, $bezier->count()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/DrawableTest.php
tests/Unit/Geometry/Factories/DrawableTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Factories\BezierFactory; use Intervention\Image\Geometry\Factories\CircleFactory; use Intervention\Image\Geometry\Factories\Drawable; use Intervention\Image\Geometry\Factories\EllipseFactory; use Intervention\Image\Geometry\Factories\LineFactory; use Intervention\Image\Geometry\Factories\PolygonFactory; use Intervention\Image\Geometry\Factories\RectangleFactory; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(BezierFactory::class)] final class DrawableTest extends BaseTestCase { public function testBezier(): void { $this->assertInstanceOf(BezierFactory::class, Drawable::bezier()); } public function testCircle(): void { $this->assertInstanceOf(CircleFactory::class, Drawable::circle()); } public function testEllipse(): void { $this->assertInstanceOf(EllipseFactory::class, Drawable::ellipse()); } public function testLine(): void { $this->assertInstanceOf(LineFactory::class, Drawable::line()); } public function testPolygon(): void { $this->assertInstanceOf(PolygonFactory::class, Drawable::polygon()); } public function testRectangle(): void { $this->assertInstanceOf(RectangleFactory::class, Drawable::rectangle()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/RectangleFactoryTest.php
tests/Unit/Geometry/Factories/RectangleFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Factories\RectangleFactory; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(RectangleFactory::class)] final class RectangleFactoryTest extends BaseTestCase { public function testFactoryCallback(): void { $factory = new RectangleFactory(new Point(1, 2), function ($rectangle): void { $rectangle->background('fff'); $rectangle->border('ccc', 10); $rectangle->width(100); $rectangle->height(200); $rectangle->size(1000, 2000); }); $rectangle = $factory(); $this->assertInstanceOf(Rectangle::class, $rectangle); $this->assertTrue($rectangle->hasBackgroundColor()); $this->assertEquals('fff', $rectangle->backgroundColor()); $this->assertEquals('ccc', $rectangle->borderColor()); $this->assertEquals(10, $rectangle->borderSize()); $this->assertEquals(1000, $rectangle->width()); $this->assertEquals(2000, $rectangle->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/EllipseFactoryTest.php
tests/Unit/Geometry/Factories/EllipseFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Factories\EllipseFactory; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(EllipseFactory::class)] final class EllipseFactoryTest extends BaseTestCase { public function testFactoryCallback(): void { $factory = new EllipseFactory(new Point(1, 2), function ($ellipse): void { $ellipse->background('fff'); $ellipse->border('ccc', 10); $ellipse->width(100); $ellipse->height(200); $ellipse->size(1000, 2000); }); $ellipse = $factory(); $this->assertInstanceOf(Ellipse::class, $ellipse); $this->assertTrue($ellipse->hasBackgroundColor()); $this->assertEquals('fff', $ellipse->backgroundColor()); $this->assertEquals('ccc', $ellipse->borderColor()); $this->assertEquals(10, $ellipse->borderSize()); $this->assertEquals(1000, $ellipse->width()); $this->assertEquals(2000, $ellipse->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/LineFactoryTest.php
tests/Unit/Geometry/Factories/LineFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Factories\LineFactory; use Intervention\Image\Geometry\Line; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(LineFactory::class)] final class LineFactoryTest extends BaseTestCase { public function testFactoryCallback(): void { $factory = new LineFactory(function ($line): void { $line->color('fff'); $line->background('fff'); $line->border('fff', 10); $line->width(10); $line->from(100, 200); $line->to(300, 400); }); $line = $factory(); $this->assertInstanceOf(Line::class, $line); $this->assertTrue($line->hasBackgroundColor()); $this->assertEquals('fff', $line->backgroundColor()); $this->assertEquals(100, $line->start()->x()); $this->assertEquals(200, $line->start()->y()); $this->assertEquals(300, $line->end()->x()); $this->assertEquals(400, $line->end()->y()); $this->assertEquals(10, $line->width()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/PolygonFactoryTest.php
tests/Unit/Geometry/Factories/PolygonFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Factories\PolygonFactory; use Intervention\Image\Geometry\Polygon; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(PolygonFactory::class)] final class PolygonFactoryTest extends BaseTestCase { public function testFactoryCallback(): void { $factory = new PolygonFactory(function ($polygon): void { $polygon->background('fff'); $polygon->border('ccc', 10); $polygon->point(1, 2); $polygon->point(3, 4); $polygon->point(5, 6); }); $polygon = $factory(); $this->assertInstanceOf(Polygon::class, $polygon); $this->assertTrue($polygon->hasBackgroundColor()); $this->assertEquals('fff', $polygon->backgroundColor()); $this->assertEquals('ccc', $polygon->borderColor()); $this->assertEquals(10, $polygon->borderSize()); $this->assertEquals(3, $polygon->count()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Geometry/Factories/CircleFactoryTest.php
tests/Unit/Geometry/Factories/CircleFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Geometry\Factories; use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Factories\CircleFactory; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(CircleFactory::class)] final class CircleFactoryTest extends BaseTestCase { public function testFactoryCallback(): void { $factory = new CircleFactory(new Point(1, 2), function ($circle): void { $circle->background('fff'); $circle->border('ccc', 10); $circle->radius(100); $circle->diameter(1000); }); $circle = $factory(); $this->assertInstanceOf(Ellipse::class, $circle); $this->assertTrue($circle->hasBackgroundColor()); $this->assertEquals('fff', $circle->backgroundColor()); $this->assertEquals('ccc', $circle->borderColor()); $this->assertEquals(10, $circle->borderSize()); $this->assertEquals(1000, $circle->width()); $this->assertEquals(1000, $circle->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Modifiers/PadModifierTest.php
tests/Unit/Modifiers/PadModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Modifiers; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Modifiers\PadModifier; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(PadModifier::class)] final class PadModifierTest extends BaseTestCase { public function testGetCropSize(): void { $modifier = new PadModifier(300, 200); $image = Mockery::mock(ImageInterface::class); $size = new Rectangle(300, 200); $image->shouldReceive('size')->andReturn($size); $this->assertInstanceOf(SizeInterface::class, $modifier->getCropSize($image)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Modifiers/TextModifierTest.php
tests/Unit/Modifiers/TextModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Modifiers; use Intervention\Image\Geometry\Point; use Intervention\Image\Interfaces\FontInterface; use Intervention\Image\Modifiers\TextModifier; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(TextModifier::class)] final class TextModifierTest extends BaseTestCase { public function testStrokeOffsets(): void { $modifier = new class ('test', new Point(), new Font()) extends TextModifier { /** * @return array<?Point> */ public function testStrokeOffsets(FontInterface $font): array { return $this->strokeOffsets($font); } }; $this->assertEquals([], $modifier->testStrokeOffsets(new Font())); $this->assertEquals([ new Point(-1, -1), new Point(-1, 0), new Point(-1, 1), new Point(0, -1), new Point(0, 0), new Point(0, 1), new Point(1, -1), new Point(1, 0), new Point(1, 1), ], $modifier->testStrokeOffsets((new Font())->setStrokeWidth(1))); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Modifiers/ColorspaceModifierTest.php
tests/Unit/Modifiers/ColorspaceModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Modifiers; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Modifiers\ColorspaceModifier; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(ColorspaceModifier::class)] final class ColorspaceModifierTest extends BaseTestCase { public function testTargetColorspace(): void { $modifier = new ColorspaceModifier(new Colorspace()); $this->assertInstanceOf(ColorspaceInterface::class, $modifier->targetColorspace()); $modifier = new ColorspaceModifier('rgb'); $this->assertInstanceOf(ColorspaceInterface::class, $modifier->targetColorspace()); $modifier = new ColorspaceModifier('cmyk'); $this->assertInstanceOf(ColorspaceInterface::class, $modifier->targetColorspace()); $modifier = new ColorspaceModifier('test'); $this->expectException(NotSupportedException::class); $modifier->targetColorspace(); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Modifiers/RemoveAnimationModifierTest.php
tests/Unit/Modifiers/RemoveAnimationModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Modifiers; use Generator; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Modifiers\RemoveAnimationModifier; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(RemoveAnimationModifier::class)] final class RemoveAnimationModifierTest extends BaseTestCase { #[DataProvider('normalizePositionProvider')] public function testNormalizePosition(int|string $position, int $frames, int $normalized): void { $modifier = new class ($position) extends RemoveAnimationModifier { public function testResult(int $frames): int { $image = Mockery::mock(ImageInterface::class)->makePartial(); $image->shouldReceive('count')->andReturn($frames); return $this->normalizePosition($image); } }; $this->assertEquals($normalized, $modifier->testResult($frames)); } public static function normalizePositionProvider(): Generator { yield [0, 100, 0]; yield [10, 100, 10]; yield ['10', 100, 10]; yield ['0%', 100, 0]; yield ['50%', 100, 50]; yield ['100%', 100, 99]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Typography/FontTest.php
tests/Unit/Typography/FontTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Typography; use Intervention\Image\Exceptions\FontException; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Font::class)] final class FontTest extends BaseTestCase { public function testConstructor(): void { $font = new Font('foo.ttf'); $this->assertInstanceOf(Font::class, $font); $this->assertEquals('foo.ttf', $font->filename()); } public function testSetGetSize(): void { $font = new Font(); $this->assertEquals(12, $font->size()); $result = $font->setSize(123); $this->assertInstanceOf(Font::class, $result); $this->assertEquals(123, $font->size()); } public function testSetGetAngle(): void { $font = new Font(); $this->assertEquals(0, $font->angle()); $result = $font->setAngle(123); $this->assertInstanceOf(Font::class, $result); $this->assertEquals(123, $font->angle()); } public function testSetGetFilename(): void { $font = new Font(); $this->assertEquals(null, $font->filename()); $this->assertFalse($font->hasFilename()); $filename = $this->getTestResourcePath(); $result = $font->setFilename($filename); $this->assertTrue($font->hasFilename()); $this->assertInstanceOf(Font::class, $result); $this->assertEquals($filename, $font->filename()); } public function testSetGetColor(): void { $font = new Font(); $this->assertEquals('000000', $font->color()); $result = $font->setColor('fff'); $this->assertInstanceOf(Font::class, $result); $this->assertEquals('fff', $font->color()); } public function testSetGetAlignment(): void { $font = new Font(); $this->assertEquals('left', $font->alignment()); $result = $font->setAlignment('center'); $this->assertInstanceOf(Font::class, $result); $this->assertEquals('center', $font->alignment()); } public function testSetGetValignment(): void { $font = new Font(); $this->assertEquals('bottom', $font->valignment()); $result = $font->setValignment('center'); $this->assertInstanceOf(Font::class, $result); $this->assertEquals('center', $font->valignment()); } public function testSetGetLineHeight(): void { $font = new Font(); $this->assertEquals(1.25, $font->lineHeight()); $result = $font->setLineHeight(3.2); $this->assertInstanceOf(Font::class, $result); $this->assertEquals(3.2, $font->lineHeight()); } public function testSetGetStrokeColor(): void { $font = new Font(); $this->assertEquals('ffffff', $font->strokeColor()); $result = $font->setStrokeColor('000000'); $this->assertInstanceOf(Font::class, $result); $this->assertEquals('000000', $font->strokeColor()); } public function testSetGetStrokeWidth(): void { $font = new Font(); $this->assertEquals(0, $font->strokeWidth()); $result = $font->setStrokeWidth(4); $this->assertInstanceOf(Font::class, $result); $this->assertEquals(4, $font->strokeWidth()); } public function testSetStrokeWidthOutOfRange(): void { $font = new Font(); $this->expectException(FontException::class); $font->setStrokeWidth(11); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Typography/FontFactoryTest.php
tests/Unit/Typography/FontFactoryTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Typography; use Intervention\Image\Interfaces\FontInterface; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; use Intervention\Image\Typography\FontFactory; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(FontFactory::class)] final class FontFactoryTest extends BaseTestCase { public function testBuildWithFont(): void { $font_file = $this->getTestResourcePath('test.ttf'); $factory = new FontFactory(new Font($font_file)); $result = $factory(); $this->assertInstanceOf(FontInterface::class, $result); $this->assertEquals($font_file, $result->filename()); } public function testBuildWithCallback(): void { $factory = new FontFactory(function (FontFactory $font): void { $font->filename($this->getTestResourcePath('test.ttf')); $font->color('#b01735'); $font->size(70); $font->align('center'); $font->valign('middle'); $font->lineHeight(1.6); $font->angle(10); $font->wrap(100); $font->stroke('ff5500', 4); }); $result = $factory(); $this->assertInstanceOf(FontInterface::class, $result); $this->assertEquals($this->getTestResourcePath('test.ttf'), $result->filename()); $this->assertEquals('#b01735', $result->color()); $this->assertEquals(70, $result->size()); $this->assertEquals('center', $result->alignment()); $this->assertEquals('middle', $result->valignment()); $this->assertEquals(1.6, $result->lineHeight()); $this->assertEquals(10, $result->angle()); $this->assertEquals(100, $result->wrapWidth()); $this->assertEquals(4, $result->strokeWidth()); $this->assertEquals('ff5500', $result->strokeColor()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Typography/TextBlockTest.php
tests/Unit/Typography/TextBlockTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Typography; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\TextBlock; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(TextBlock::class)] final class TextBlockTest extends BaseTestCase { protected TextBlock $block; protected function setUp(): void { $this->block = new TextBlock(<<<EOF foo FooBar bar EOF); } public function testCount(): void { $this->assertEquals(3, $this->block->count()); } public function testLines(): void { $this->assertCount(3, $this->block->lines()); } public function testGetLine(): void { $this->assertEquals('foo', $this->block->line(0)); $this->assertEquals('FooBar', $this->block->line(1)); $this->assertEquals('bar', $this->block->line(2)); $this->assertNull($this->block->line(20)); } public function testLongestLine(): void { $result = $this->block->longestLine(); $this->assertEquals('FooBar', (string) $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Typography/LineTest.php
tests/Unit/Typography/LineTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Typography; use Generator; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Line; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(Line::class)] final class LineTest extends BaseTestCase { public function testConstructor(): void { $line = new Line('foo'); $this->assertInstanceOf(Line::class, $line); } #[DataProvider('toStringDataProvider')] public function testToString(string $text, int $words): void { $line = new Line($text); $this->assertEquals($words, $line->count()); $this->assertEquals($text, (string) $line); } public function testSetGetPosition(): void { $line = new Line('foo'); $this->assertEquals(0, $line->position()->x()); $this->assertEquals(0, $line->position()->y()); $line->setPosition(new Point(10, 11)); $this->assertEquals(10, $line->position()->x()); $this->assertEquals(11, $line->position()->y()); } public function testCount(): void { $line = new Line(); $this->assertEquals(0, $line->count()); $line = new Line("foo"); $this->assertEquals(1, $line->count()); $line = new Line("foo bar"); $this->assertEquals(2, $line->count()); } public function testLength(): void { $line = new Line(); $this->assertEquals(0, $line->length()); $line = new Line("foo"); $this->assertEquals(3, $line->length()); $line = new Line("foo bar."); $this->assertEquals(8, $line->length()); $line = new Line("🫷🙂🫸"); $this->assertEquals(3, $line->length()); } public function testAdd(): void { $line = new Line(); $this->assertEquals(0, $line->count()); $result = $line->add('foo'); $this->assertEquals(1, $line->count()); $this->assertEquals(1, $result->count()); $result = $line->add('bar'); $this->assertEquals(2, $line->count()); $this->assertEquals(2, $result->count()); } public static function toStringDataProvider(): Generator { yield ['foo', 1]; yield ['foo bar', 2]; yield ['测试', 2]; // CJK Unified Ideographs yield ['テスト', 3]; // japanese yield ['ทดสอบ', 5]; // thai yield ['这只是我写的一个测试。', 11]; // CJK Unified Ideographs } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/mocked-functions.php
mocked-functions.php
<?php namespace League\Flysystem\Local { function rmdir(...$arguments) { if ( ! is_mocked('rmdir')) { return \rmdir(...$arguments); } return return_mocked_value('rmdir'); } function unlink(...$arguments) { if ( ! is_mocked('unlink')) { return \unlink(...$arguments); } return return_mocked_value('unlink'); } function filemtime(...$arguments) { if ( ! is_mocked('filemtime')) { return \filemtime(...$arguments); } return return_mocked_value('filemtime'); } function filesize(...$arguments) { if ( ! is_mocked('filesize')) { return \filesize(...$arguments); } return return_mocked_value('filesize'); } } namespace League\Flysystem\InMemory { function time() { if ( ! is_mocked('time')) { return \time(); } return return_mocked_value('time'); } } namespace League\Flysystem\Ftp { function ftp_raw(...$arguments) { if ( ! is_mocked('ftp_raw')) { return \ftp_raw(...$arguments); } return return_mocked_value('ftp_raw'); } function ftp_set_option(...$arguments) { if ( ! is_mocked('ftp_set_option')) { return \ftp_set_option(...$arguments); } return return_mocked_value('ftp_set_option'); } function ftp_pasv(...$arguments) { if ( ! is_mocked('ftp_pasv')) { return \ftp_pasv(...$arguments); } return return_mocked_value('ftp_pasv'); } function ftp_pwd(...$arguments) { if ( ! is_mocked('ftp_pwd')) { return \ftp_pwd(...$arguments); } return return_mocked_value('ftp_pwd'); } function ftp_fput(...$arguments) { if ( ! is_mocked('ftp_fput')) { return \ftp_fput(...$arguments); } return return_mocked_value('ftp_fput'); } function ftp_chmod(...$arguments) { if ( ! is_mocked('ftp_chmod')) { return \ftp_chmod(...$arguments); } return return_mocked_value('ftp_chmod'); } function ftp_mkdir(...$arguments) { if ( ! is_mocked('ftp_mkdir')) { return \ftp_mkdir(...$arguments); } return return_mocked_value('ftp_mkdir'); } function ftp_delete(...$arguments) { if ( ! is_mocked('ftp_delete')) { return \ftp_delete(...$arguments); } return return_mocked_value('ftp_delete'); } function ftp_rmdir(...$arguments) { if ( ! is_mocked('ftp_rmdir')) { return \ftp_rmdir(...$arguments); } return return_mocked_value('ftp_rmdir'); } function ftp_fget(...$arguments) { if ( ! is_mocked('ftp_fget')) { return \ftp_fget(...$arguments); } return return_mocked_value('ftp_fget'); } function ftp_rawlist(...$arguments) { if ( ! is_mocked('ftp_rawlist')) { return \ftp_rawlist(...$arguments); } return return_mocked_value('ftp_rawlist'); } } namespace League\Flysystem\ZipArchive { function stream_get_contents(...$arguments) { if ( ! is_mocked('stream_get_contents')) { return \stream_get_contents(...$arguments); } return return_mocked_value('stream_get_contents'); } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/.php-cs-fixer.dist.php
.php-cs-fixer.dist.php
<?php $finder = PhpCsFixer\Finder::create() ->in([__DIR__ . '/']) ->exclude(__DIR__ . '/vendor'); return (new PhpCsFixer\Config()) ->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => true, 'single_line_after_imports' => true, 'blank_line_before_statement' => ['statements' => ['return']], 'cast_spaces' => true, 'concat_space' => ['spacing' => 'one'], 'no_singleline_whitespace_before_semicolons' => true, 'not_operator_with_space' => true, 'no_unused_imports' => true, 'phpdoc_align' => false, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_alias_tag' => true, 'phpdoc_no_package' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'single_blank_line_at_eof' => true, 'ternary_operator_spaces' => true, 'ordered_imports' => [ 'sort_algorithm' => 'alpha', 'imports_order' => ['const', 'class', 'function'], ], 'no_extra_blank_lines' => true, 'no_whitespace_in_blank_line' => true, 'nullable_type_declaration_for_default_null_value' => true, ]) ->setFinder($finder);
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/phpunit.php
phpunit.php
<?php include __DIR__ . '/vendor/autoload.php'; include __DIR__ . '/src/AdapterTestUtilities/test-functions.php'; include __DIR__ . '/mocked-functions.php';
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/test_files/wait_for_ftp.php
test_files/wait_for_ftp.php
<?php use League\Flysystem\Ftp\FtpConnectionOptions; use League\Flysystem\Ftp\FtpConnectionProvider; include __DIR__ . '/../vendor/autoload.php'; $options = FtpConnectionOptions::fromArray([ 'host' => 'localhost', 'port' => (int) ($argv[1] ?? 2122), 'root' => '/', 'username' => 'foo', 'password' => 'pass', ]); $provider = new FtpConnectionProvider(); $start = time(); $connected = false; while (time() - $start < 60) { try { $provider->createConnection($options); $connected = true; break; } catch (Throwable $exception) { if (time() - $start < 30) { fwrite(STDOUT, "Exception while trying to connect:'\n"); fwrite(STDOUT, (string) $exception); fwrite(STDOUT, "\n\n"); } usleep(10000); } } if ( ! $connected) { fwrite(STDERR, "Unable to start FTP server.\n"); exit(1); } fwrite(STDOUT, "Detected FTP server successfully.\n");
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/test_files/wait_for_sftp.php
test_files/wait_for_sftp.php
<?php use League\Flysystem\PhpseclibV2\SftpConnectionProvider as V2Provider; use League\Flysystem\PhpseclibV3\SftpConnectionProvider as V3Provider; use phpseclib3\Net\SFTP; include __DIR__ . '/../vendor/autoload.php'; $providerName = class_exists(SFTP::class) ? V3Provider::class : V2Provider::class; $connectionProvider = $providerName::fromArray( [ 'host' => 'localhost', 'username' => 'foo', 'password' => 'pass', 'port' => 2222, ] ); $start = time(); $connected = false; while (time() - $start < 60) { try { $connectionProvider->provideConnection(); $connected = true; break; } catch (Throwable $exception) { echo($exception); usleep(10000); } } if ( ! $connected) { fwrite(STDERR, "Unable to start SFTP server.\n"); exit(1); } fwrite(STDOUT, "Detected SFTP server successfully.\n");
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/UnableToListContents.php
src/UnableToListContents.php
<?php declare(strict_types=1); namespace League\Flysystem; use RuntimeException; use Throwable; final class UnableToListContents extends RuntimeException implements FilesystemOperationFailed { public static function atLocation(string $location, bool $deep, Throwable $previous): UnableToListContents { $message = "Unable to list contents for '$location', " . ($deep ? 'deep' : 'shallow') . " listing\n\n" . 'Reason: ' . $previous->getMessage(); return new UnableToListContents($message, 0, $previous); } public function operation(): string { return self::OPERATION_LIST_CONTENTS; } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/SymbolicLinkEncountered.php
src/SymbolicLinkEncountered.php
<?php declare(strict_types=1); namespace League\Flysystem; use RuntimeException; final class SymbolicLinkEncountered extends RuntimeException implements FilesystemException { private string $location; public function location(): string { return $this->location; } public static function atLocation(string $pathName): SymbolicLinkEncountered { $e = new static("Unsupported symbolic link encountered at location $pathName"); $e->location = $pathName; return $e; } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/Filesystem.php
src/Filesystem.php
<?php declare(strict_types=1); namespace League\Flysystem; use DateTimeInterface; use Generator; use League\Flysystem\UrlGeneration\PrefixPublicUrlGenerator; use League\Flysystem\UrlGeneration\PublicUrlGenerator; use League\Flysystem\UrlGeneration\ShardedPrefixPublicUrlGenerator; use League\Flysystem\UrlGeneration\TemporaryUrlGenerator; use Throwable; use function array_key_exists; use function is_array; class Filesystem implements FilesystemOperator { use CalculateChecksumFromStream; private Config $config; private PathNormalizer $pathNormalizer; public function __construct( private FilesystemAdapter $adapter, array $config = [], ?PathNormalizer $pathNormalizer = null, private ?PublicUrlGenerator $publicUrlGenerator = null, private ?TemporaryUrlGenerator $temporaryUrlGenerator = null, ) { $this->config = new Config($config); $this->pathNormalizer = $pathNormalizer ?? new WhitespacePathNormalizer(); } public function fileExists(string $location): bool { return $this->adapter->fileExists($this->pathNormalizer->normalizePath($location)); } public function directoryExists(string $location): bool { return $this->adapter->directoryExists($this->pathNormalizer->normalizePath($location)); } public function has(string $location): bool { $path = $this->pathNormalizer->normalizePath($location); return $this->adapter->fileExists($path) || $this->adapter->directoryExists($path); } public function write(string $location, string $contents, array $config = []): void { $this->adapter->write( $this->pathNormalizer->normalizePath($location), $contents, $this->config->extend($config) ); } public function writeStream(string $location, $contents, array $config = []): void { /* @var resource $contents */ $this->assertIsResource($contents); $this->rewindStream($contents); $this->adapter->writeStream( $this->pathNormalizer->normalizePath($location), $contents, $this->config->extend($config) ); } public function read(string $location): string { return $this->adapter->read($this->pathNormalizer->normalizePath($location)); } public function readStream(string $location) { return $this->adapter->readStream($this->pathNormalizer->normalizePath($location)); } public function delete(string $location): void { $this->adapter->delete($this->pathNormalizer->normalizePath($location)); } public function deleteDirectory(string $location): void { $this->adapter->deleteDirectory($this->pathNormalizer->normalizePath($location)); } public function createDirectory(string $location, array $config = []): void { $this->adapter->createDirectory( $this->pathNormalizer->normalizePath($location), $this->config->extend($config) ); } public function listContents(string $location, bool $deep = self::LIST_SHALLOW): DirectoryListing { $path = $this->pathNormalizer->normalizePath($location); $listing = $this->adapter->listContents($path, $deep); return new DirectoryListing($this->pipeListing($location, $deep, $listing)); } private function pipeListing(string $location, bool $deep, iterable $listing): Generator { try { foreach ($listing as $item) { yield $item; } } catch (Throwable $exception) { throw UnableToListContents::atLocation($location, $deep, $exception); } } public function move(string $source, string $destination, array $config = []): void { $config = $this->resolveConfigForMoveAndCopy($config); $from = $this->pathNormalizer->normalizePath($source); $to = $this->pathNormalizer->normalizePath($destination); if ($from === $to) { $resolutionStrategy = $config->get(Config::OPTION_MOVE_IDENTICAL_PATH, ResolveIdenticalPathConflict::TRY); if ($resolutionStrategy === ResolveIdenticalPathConflict::FAIL) { throw UnableToMoveFile::sourceAndDestinationAreTheSame($source, $destination); } elseif ($resolutionStrategy === ResolveIdenticalPathConflict::IGNORE) { return; } } $this->adapter->move($from, $to, $config); } public function copy(string $source, string $destination, array $config = []): void { $config = $this->resolveConfigForMoveAndCopy($config); $from = $this->pathNormalizer->normalizePath($source); $to = $this->pathNormalizer->normalizePath($destination); if ($from === $to) { $resolutionStrategy = $config->get(Config::OPTION_COPY_IDENTICAL_PATH, ResolveIdenticalPathConflict::TRY); if ($resolutionStrategy === ResolveIdenticalPathConflict::FAIL) { throw UnableToCopyFile::sourceAndDestinationAreTheSame($source, $destination); } elseif ($resolutionStrategy === ResolveIdenticalPathConflict::IGNORE) { return; } } $this->adapter->copy($from, $to, $config); } public function lastModified(string $path): int { return $this->adapter->lastModified($this->pathNormalizer->normalizePath($path))->lastModified(); } public function fileSize(string $path): int { return $this->adapter->fileSize($this->pathNormalizer->normalizePath($path))->fileSize(); } public function mimeType(string $path): string { return $this->adapter->mimeType($this->pathNormalizer->normalizePath($path))->mimeType(); } public function setVisibility(string $path, string $visibility): void { $this->adapter->setVisibility($this->pathNormalizer->normalizePath($path), $visibility); } public function visibility(string $path): string { return $this->adapter->visibility($this->pathNormalizer->normalizePath($path))->visibility(); } public function publicUrl(string $path, array $config = []): string { $this->publicUrlGenerator ??= $this->resolvePublicUrlGenerator() ?? throw UnableToGeneratePublicUrl::noGeneratorConfigured($path); $config = $this->config->extend($config); return $this->publicUrlGenerator->publicUrl( $this->pathNormalizer->normalizePath($path), $config, ); } public function temporaryUrl(string $path, DateTimeInterface $expiresAt, array $config = []): string { $generator = $this->temporaryUrlGenerator ?? $this->adapter; if ($generator instanceof TemporaryUrlGenerator) { return $generator->temporaryUrl( $this->pathNormalizer->normalizePath($path), $expiresAt, $this->config->extend($config) ); } throw UnableToGenerateTemporaryUrl::noGeneratorConfigured($path); } public function checksum(string $path, array $config = []): string { $config = $this->config->extend($config); if ( ! $this->adapter instanceof ChecksumProvider) { return $this->calculateChecksumFromStream($path, $config); } try { return $this->adapter->checksum( $this->pathNormalizer->normalizePath($path), $config, ); } catch (ChecksumAlgoIsNotSupported) { return $this->calculateChecksumFromStream( $this->pathNormalizer->normalizePath($path), $config, ); } } private function resolvePublicUrlGenerator(): ?PublicUrlGenerator { if ($publicUrl = $this->config->get('public_url')) { return match (true) { is_array($publicUrl) => new ShardedPrefixPublicUrlGenerator($publicUrl), default => new PrefixPublicUrlGenerator($publicUrl), }; } if ($this->adapter instanceof PublicUrlGenerator) { return $this->adapter; } return null; } /** * @param mixed $contents */ private function assertIsResource($contents): void { if (is_resource($contents) === false) { throw new InvalidStreamProvided( "Invalid stream provided, expected stream resource, received " . gettype($contents) ); } elseif ($type = get_resource_type($contents) !== 'stream') { throw new InvalidStreamProvided( "Invalid stream provided, expected stream resource, received resource of type " . $type ); } } /** * @param resource $resource */ private function rewindStream($resource): void { if (ftell($resource) !== 0 && stream_get_meta_data($resource)['seekable']) { rewind($resource); } } private function resolveConfigForMoveAndCopy(array $config): Config { $retainVisibility = $this->config->get(Config::OPTION_RETAIN_VISIBILITY, $config[Config::OPTION_RETAIN_VISIBILITY] ?? true); $fullConfig = $this->config->extend($config); /* * By default, we retain visibility. When we do not retain visibility, the visibility setting * from the default configuration is ignored. Only when it is set explicitly, we propagate the * setting. */ if ($retainVisibility && ! array_key_exists(Config::OPTION_VISIBILITY, $config)) { $fullConfig = $fullConfig->withoutSettings(Config::OPTION_VISIBILITY)->extend($config); } return $fullConfig; } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/UnableToMountFilesystem.php
src/UnableToMountFilesystem.php
<?php declare(strict_types=1); namespace League\Flysystem; use LogicException; class UnableToMountFilesystem extends LogicException implements FilesystemException { /** * @param mixed $key */ public static function becauseTheKeyIsNotValid($key): UnableToMountFilesystem { return new UnableToMountFilesystem( 'Unable to mount filesystem, key was invalid. String expected, received: ' . gettype($key) ); } /** * @param mixed $filesystem */ public static function becauseTheFilesystemWasNotValid($filesystem): UnableToMountFilesystem { $received = is_object($filesystem) ? get_class($filesystem) : gettype($filesystem); return new UnableToMountFilesystem( 'Unable to mount filesystem, filesystem was invalid. Instance of ' . FilesystemOperator::class . ' expected, received: ' . $received ); } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/DirectoryAttributes.php
src/DirectoryAttributes.php
<?php declare(strict_types=1); namespace League\Flysystem; class DirectoryAttributes implements StorageAttributes { use ProxyArrayAccessToProperties; private string $type = StorageAttributes::TYPE_DIRECTORY; public function __construct( private string $path, private ?string $visibility = null, private ?int $lastModified = null, private array $extraMetadata = [] ) { $this->path = trim($this->path, '/'); } public function path(): string { return $this->path; } public function type(): string { return $this->type; } public function visibility(): ?string { return $this->visibility; } public function lastModified(): ?int { return $this->lastModified; } public function extraMetadata(): array { return $this->extraMetadata; } public function isFile(): bool { return false; } public function isDir(): bool { return true; } public function withPath(string $path): self { $clone = clone $this; $clone->path = $path; return $clone; } public static function fromArray(array $attributes): self { return new DirectoryAttributes( $attributes[StorageAttributes::ATTRIBUTE_PATH], $attributes[StorageAttributes::ATTRIBUTE_VISIBILITY] ?? null, $attributes[StorageAttributes::ATTRIBUTE_LAST_MODIFIED] ?? null, $attributes[StorageAttributes::ATTRIBUTE_EXTRA_METADATA] ?? [] ); } /** * @inheritDoc */ public function jsonSerialize(): array { return [ StorageAttributes::ATTRIBUTE_TYPE => $this->type, StorageAttributes::ATTRIBUTE_PATH => $this->path, StorageAttributes::ATTRIBUTE_VISIBILITY => $this->visibility, StorageAttributes::ATTRIBUTE_LAST_MODIFIED => $this->lastModified, StorageAttributes::ATTRIBUTE_EXTRA_METADATA => $this->extraMetadata, ]; } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/FilesystemReader.php
src/FilesystemReader.php
<?php declare(strict_types=1); namespace League\Flysystem; use DateTimeInterface; /** * This interface contains everything to read from and inspect * a filesystem. All methods containing are non-destructive. * * @method string publicUrl(string $path, array $config = []) Will be added in 4.0 * @method string temporaryUrl(string $path, DateTimeInterface $expiresAt, array $config = []) Will be added in 4.0 * @method string checksum(string $path, array $config = []) Will be added in 4.0 */ interface FilesystemReader { public const LIST_SHALLOW = false; public const LIST_DEEP = true; /** * @throws FilesystemException * @throws UnableToCheckExistence */ public function fileExists(string $location): bool; /** * @throws FilesystemException * @throws UnableToCheckExistence */ public function directoryExists(string $location): bool; /** * @throws FilesystemException * @throws UnableToCheckExistence */ public function has(string $location): bool; /** * @throws UnableToReadFile * @throws FilesystemException */ public function read(string $location): string; /** * @return resource * * @throws UnableToReadFile * @throws FilesystemException */ public function readStream(string $location); /** * @return DirectoryListing<StorageAttributes> * * @throws FilesystemException * @throws UnableToListContents */ public function listContents(string $location, bool $deep = self::LIST_SHALLOW): DirectoryListing; /** * @throws UnableToRetrieveMetadata * @throws FilesystemException */ public function lastModified(string $path): int; /** * @throws UnableToRetrieveMetadata * @throws FilesystemException */ public function fileSize(string $path): int; /** * @throws UnableToRetrieveMetadata * @throws FilesystemException */ public function mimeType(string $path): string; /** * @throws UnableToRetrieveMetadata * @throws FilesystemException */ public function visibility(string $path): string; }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/MountManagerTest.php
src/MountManagerTest.php
<?php namespace League\Flysystem; use League\Flysystem\AdapterTestUtilities\ExceptionThrowingFilesystemAdapter; use League\Flysystem\InMemory\InMemoryFilesystemAdapter; use PHPUnit\Framework\TestCase; use function fclose; use function is_resource; use function stream_get_contents; use function tmpfile; /** * @group core */ class MountManagerTest extends TestCase { /** * @var ExceptionThrowingFilesystemAdapter */ private $firstStubAdapter; /** * @var ExceptionThrowingFilesystemAdapter */ private $secondStubAdapter; /** * @var MountManager */ private $mountManager; /** * @var Filesystem */ private $firstFilesystem; /** * @var Filesystem */ private $secondFilesystem; protected function setUp(): void { $firstFilesystemAdapter = new InMemoryFilesystemAdapter(); $secondFilesystemAdapter = new InMemoryFilesystemAdapter(); $this->firstStubAdapter = new ExceptionThrowingFilesystemAdapter($firstFilesystemAdapter); $this->secondStubAdapter = new ExceptionThrowingFilesystemAdapter($secondFilesystemAdapter); $this->mountManager = new MountManager([ 'first' => $this->firstFilesystem = new Filesystem($this->firstStubAdapter), 'second' => $this->secondFilesystem = new Filesystem($this->secondStubAdapter), ]); } /** * @test */ public function copying_without_retaining_visibility(): void { // arrange $firstFilesystemAdapter = new InMemoryFilesystemAdapter(); $secondFilesystemAdapter = new InMemoryFilesystemAdapter(); $mountManager = new MountManager([ 'first' => new Filesystem($firstFilesystemAdapter, ['visibility' => 'public']), 'second' => new Filesystem($secondFilesystemAdapter, ['visibility' => 'private']), ], ['retain_visibility' => false]); // act $mountManager->write('first://file.txt', 'contents'); $mountManager->copy('first://file.txt', 'second://file.txt'); // assert $visibility = $mountManager->visibility('second://file.txt'); self::assertEquals('private', $visibility); } /** * @test */ public function extending_without_new_mounts_is_equal_but_not_the_same(): void { $mountManager = $this->mountManager->extend([]); $this->assertNotSame($this->mountManager, $mountManager); $this->assertEquals($this->mountManager, $mountManager); } /** * @test */ public function extending_with_new_mounts_is_not_equal(): void { $mountManager = $this->mountManager->extend([ 'third' => new Filesystem(new InMemoryFilesystemAdapter()), ]); $this->assertNotEquals($this->mountManager, $mountManager); } /** * @test */ public function extending_exposes_a_usable_mount_on_the_extension(): void { $mountManager = $this->mountManager->extend([ 'third' => new Filesystem(new InMemoryFilesystemAdapter()), ]); $mountManager->write('third://path.txt', 'this'); $contents = $mountManager->read('third://path.txt'); $this->assertEquals('this', $contents); } /** * @test */ public function extending_does_not_mount_on_the_original_mount_manager(): void { $this->mountManager->extend([ 'third' => new Filesystem(new InMemoryFilesystemAdapter()), ]); $this->expectException(UnableToResolveFilesystemMount::class); $this->mountManager->write('third://path.txt', 'this'); } /** * @test */ public function copying_while_retaining_visibility(): void { // arrange $firstFilesystemAdapter = new InMemoryFilesystemAdapter(); $secondFilesystemAdapter = new InMemoryFilesystemAdapter(); $mountManager = new MountManager([ 'first' => new Filesystem($firstFilesystemAdapter, ['visibility' => 'public']), 'second' => new Filesystem($secondFilesystemAdapter, ['visibility' => 'private']), ], ['retain_visibility' => true]); // act $mountManager->write('first://file.txt', 'contents'); $mountManager->copy('first://file.txt', 'second://file.txt'); // assert $visibility = $mountManager->visibility('second://file.txt'); self::assertEquals('public', $visibility); } /** * @test */ public function writing_a_file(): void { $this->mountManager->write('first://file.txt', 'content'); $this->mountManager->write('second://another-file.txt', 'content'); $this->assertTrue($this->firstFilesystem->fileExists('file.txt')); $this->assertFalse($this->secondFilesystem->fileExists('file.txt')); $this->assertFalse($this->firstFilesystem->fileExists('another-file.txt')); $this->assertTrue($this->secondFilesystem->fileExists('another-file.txt')); } /** * @test */ public function writing_a_file_with_a_stream(): void { $stream = stream_with_contents('contents'); $this->mountManager->writeStream('first://location.txt', $stream); $this->assertTrue($this->firstFilesystem->fileExists('location.txt')); $this->assertEquals('contents', $this->firstFilesystem->read('location.txt')); } /** * @test */ public function not_being_able_to_write_a_file(): void { $this->firstStubAdapter->stageException('write', 'file.txt', UnableToWriteFile::atLocation('file.txt')); $this->expectException(UnableToWriteFile::class); $this->mountManager->write('first://file.txt', 'content'); } /** * @test */ public function not_being_able_to_stream_write_a_file(): void { $handle = tmpfile(); $this->firstStubAdapter->stageException('writeStream', 'file.txt', UnableToWriteFile::atLocation('file.txt')); $this->expectException(UnableToWriteFile::class); try { $this->mountManager->writeStream('first://file.txt', $handle); } finally { is_resource($handle) && fclose($handle); } } /** * @description This test method is so ugly, but I don't have the energy to create a nice test for every single one of these method. * * @test * * @dataProvider dpMetadataRetrieverMethods */ public function failing_a_one_param_method(string $method, FilesystemOperationFailed $exception): void { $this->firstStubAdapter->stageException($method, 'location.txt', $exception); $this->expectException(get_class($exception)); $this->mountManager->{$method}('first://location.txt'); } public static function dpMetadataRetrieverMethods(): iterable { yield 'mimeType' => ['mimeType', UnableToRetrieveMetadata::mimeType('location.txt')]; yield 'fileSize' => ['fileSize', UnableToRetrieveMetadata::fileSize('location.txt')]; yield 'lastModified' => ['lastModified', UnableToRetrieveMetadata::lastModified('location.txt')]; yield 'visibility' => ['visibility', UnableToRetrieveMetadata::visibility('location.txt')]; yield 'delete' => ['delete', UnableToDeleteFile::atLocation('location.txt')]; yield 'deleteDirectory' => ['deleteDirectory', UnableToDeleteDirectory::atLocation('location.txt')]; yield 'createDirectory' => ['createDirectory', UnableToCreateDirectory::atLocation('location.txt')]; yield 'read' => ['read', UnableToReadFile::fromLocation('location.txt')]; yield 'readStream' => ['readStream', UnableToReadFile::fromLocation('location.txt')]; yield 'fileExists' => ['fileExists', UnableToCheckFileExistence::forLocation('location.txt')]; } /** * @test */ public function reading_a_file(): void { $this->secondFilesystem->write('location.txt', 'contents'); $contents = $this->mountManager->read('second://location.txt'); $this->assertEquals('contents', $contents); } /** * @test */ public function reading_a_file_as_a_stream(): void { $this->secondFilesystem->write('location.txt', 'contents'); $handle = $this->mountManager->readStream('second://location.txt'); $contents = stream_get_contents($handle); fclose($handle); $this->assertEquals('contents', $contents); } /** * @test */ public function checking_existence_for_an_existing_file(): void { $this->secondFilesystem->write('location.txt', 'contents'); $existence = $this->mountManager->fileExists('second://location.txt'); $this->assertTrue($existence); } /** * @test */ public function checking_existence_for_an_non_existing_file(): void { $existence = $this->mountManager->fileExists('second://location.txt'); $this->assertFalse($existence); } /** * @test */ public function checking_existence_for_an_non_existing_directory(): void { $existence = $this->mountManager->directoryExists('second://some-directory'); $this->assertFalse($existence); } /** * @test */ public function checking_existence_for_an_existing_directory(): void { $this->secondFilesystem->write('nested/location.txt', 'contents'); $existence = $this->mountManager->directoryExists('second://nested'); $this->assertTrue($existence); } /** * @test */ public function checking_existence_for_an_existing_file_using_has(): void { $this->secondFilesystem->write('location.txt', 'contents'); $existence = $this->mountManager->has('second://location.txt'); $this->assertTrue($existence); } /** * @test */ public function checking_existence_for_an_non_existing_file_using_has(): void { $existence = $this->mountManager->has('second://location.txt'); $this->assertFalse($existence); } /** * @test */ public function checking_existence_for_an_non_existing_directory_using_has(): void { $existence = $this->mountManager->has('second://some-directory'); $this->assertFalse($existence); } /** * @test */ public function checking_existence_for_an_existing_directory_using_has(): void { $this->secondFilesystem->write('nested/location.txt', 'contents'); $existence = $this->mountManager->has('second://nested'); $this->assertTrue($existence); } /** * @test */ public function deleting_a_file(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->mountManager->delete('first://location.txt'); $this->assertFalse($this->firstFilesystem->fileExists('location.txt')); } /** * @test */ public function deleting_a_directory(): void { $this->firstFilesystem->write('dirname/location.txt', 'contents'); $this->mountManager->deleteDirectory('first://dirname'); $this->assertFalse($this->firstFilesystem->fileExists('dirname/location.txt')); } /** * @test */ public function setting_visibility(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->firstFilesystem->setVisibility('location.txt', Visibility::PRIVATE); $this->mountManager->setVisibility('first://location.txt', Visibility::PUBLIC); $this->assertEquals(Visibility::PUBLIC, $this->firstFilesystem->visibility('location.txt')); } /** * @test */ public function retrieving_metadata(): void { $now = time(); $this->firstFilesystem->write('location.txt', 'contents'); $lastModified = $this->mountManager->lastModified('first://location.txt'); $fileSize = $this->mountManager->fileSize('first://location.txt'); $mimeType = $this->mountManager->mimeType('first://location.txt'); $this->assertGreaterThanOrEqual($now, $lastModified); $this->assertEquals(8, $fileSize); $this->assertEquals('text/plain', $mimeType); } /** * @test */ public function creating_a_directory(): void { $this->mountManager->createDirectory('first://directory'); $directoryListing = $this->firstFilesystem->listContents('/') ->toArray(); $this->assertCount(1, $directoryListing); /** @var DirectoryAttributes $directory */ $directory = $directoryListing[0]; $this->assertInstanceOf(DirectoryAttributes::class, $directory); $this->assertEquals('directory', $directory->path()); } /** * @test */ public function list_directory(): void { $this->mountManager->createDirectory('first://directory'); $this->mountManager->write('first://directory/file', 'foo'); $directoryListing = $this->mountManager->listContents('first://', Filesystem::LIST_DEEP)->toArray(); $this->assertCount(2, $directoryListing); /** @var DirectoryAttributes $directory */ $directory = $directoryListing[0]; $this->assertInstanceOf(DirectoryAttributes::class, $directory); $this->assertEquals('first://directory', $directory->path()); /** @var FileAttributes $file */ $file = $directoryListing[1]; $this->assertInstanceOf(FileAttributes::class, $file); $this->assertEquals('first://directory/file', $file->path()); } /** * @test */ public function copying_in_the_same_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->assertTrue($this->firstFilesystem->fileExists('location.txt')); $this->mountManager->copy('first://location.txt', 'first://new-location.txt'); $this->assertTrue($this->firstFilesystem->fileExists('location.txt')); $this->assertTrue($this->firstFilesystem->fileExists('new-location.txt')); } /** * @test */ public function failing_to_copy_in_the_same_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->firstStubAdapter->stageException('copy', 'location.txt', UnableToCopyFile::fromLocationTo('a', 'b')); $this->expectException(UnableToCopyFile::class); $this->mountManager->copy('first://location.txt', 'first://new-location.txt'); } /** * @test */ public function failing_to_move_in_the_same_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->firstStubAdapter->stageException('move', 'location.txt', UnableToMoveFile::fromLocationTo('a', 'b')); $this->expectException(UnableToMoveFile::class); $this->mountManager->move('first://location.txt', 'first://new-location.txt'); } /** * @test */ public function moving_in_the_same_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->assertTrue($this->firstFilesystem->fileExists('location.txt')); $this->mountManager->move('first://location.txt', 'first://new-location.txt'); $this->assertFalse($this->firstFilesystem->fileExists('location.txt')); $this->assertTrue($this->firstFilesystem->fileExists('new-location.txt')); } /** * @test */ public function moving_across_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->assertTrue($this->firstFilesystem->fileExists('location.txt')); $this->mountManager->move('first://location.txt', 'second://new-location.txt'); $this->assertFalse($this->firstFilesystem->fileExists('location.txt')); $this->assertTrue($this->secondFilesystem->fileExists('new-location.txt')); } /** * @test */ public function failing_to_move_across_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->firstStubAdapter->stageException('visibility', 'location.txt', UnableToRetrieveMetadata::visibility('location.txt')); $this->expectException(UnableToMoveFile::class); $this->mountManager->move('first://location.txt', 'second://new-location.txt'); } /** * @test */ public function failing_to_copy_across_filesystem(): void { $this->firstFilesystem->write('location.txt', 'contents'); $this->firstStubAdapter->stageException('visibility', 'location.txt', UnableToRetrieveMetadata::visibility('location.txt')); $this->expectException(UnableToCopyFile::class); $this->mountManager->copy('first://location.txt', 'second://new-location.txt'); } /** * @test */ public function listing_contents(): void { $this->firstFilesystem->write('contents.txt', 'file contents'); $this->firstFilesystem->write('dirname/contents.txt', 'file contents'); $this->secondFilesystem->write('dirname/contents.txt', 'file contents'); $contents = $this->mountManager->listContents('first://', FilesystemReader::LIST_DEEP)->toArray(); $this->assertCount(3, $contents); } /** * @test */ public function dangerously_mounting_additional_filesystems(): void { $this->firstFilesystem->write('contents.txt', 'file contents'); $this->mountManager->dangerouslyMountFilesystems('unknown', $this->firstFilesystem); $this->assertTrue($this->mountManager->fileExists('unknown://contents.txt')); } /** * @test */ public function guarding_against_valid_mount_identifiers(): void { $this->expectException(UnableToMountFilesystem::class); /* @phpstan-ignore-next-line */ new MountManager([1 => new Filesystem(new InMemoryFilesystemAdapter())]); } /** * @test */ public function guarding_against_mounting_invalid_filesystems(): void { $this->expectException(UnableToMountFilesystem::class); /* @phpstan-ignore-next-line */ new MountManager(['valid' => 'something else']); } /** * @test */ public function guarding_against_using_paths_without_mount_prefix(): void { $this->expectException(UnableToResolveFilesystemMount::class); $this->mountManager->read('path-without-mount-prefix.txt'); } /** * @test */ public function guard_against_using_unknown_mount(): void { $this->expectException(UnableToResolveFilesystemMount::class); $this->mountManager->read('unknown://location.txt'); } /** * @test */ public function generate_public_url(): void { $mountManager = new MountManager([ 'first' => new Filesystem($this->firstStubAdapter, ['public_url' => 'first.example.com']), 'second' => new Filesystem($this->secondStubAdapter, ['public_url' => 'second.example.com']), ]); $mountManager->write('first://file1.txt', 'content'); $mountManager->write('second://file2.txt', 'content'); $this->assertSame('first.example.com/file1.txt', $mountManager->publicUrl('first://file1.txt')); $this->assertSame('second.example.com/file2.txt', $mountManager->publicUrl('second://file2.txt')); } /** * @test */ public function provide_checksum(): void { $this->mountManager->write('first://file.txt', 'content'); $this->assertSame('9a0364b9e99bb480dd25e1f0284c8555', $this->mountManager->checksum('first://file.txt')); } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false
thephpleague/flysystem
https://github.com/thephpleague/flysystem/blob/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277/src/DecoratedAdapter.php
src/DecoratedAdapter.php
<?php declare(strict_types=1); namespace League\Flysystem; abstract class DecoratedAdapter implements FilesystemAdapter { public function __construct(protected FilesystemAdapter $adapter) { } public function fileExists(string $path): bool { return $this->adapter->fileExists($path); } public function directoryExists(string $path): bool { return $this->adapter->directoryExists($path); } public function write(string $path, string $contents, Config $config): void { $this->adapter->write($path, $contents, $config); } public function writeStream(string $path, $contents, Config $config): void { $this->adapter->writeStream($path, $contents, $config); } public function read(string $path): string { return $this->adapter->read($path); } public function readStream(string $path) { return $this->adapter->readStream($path); } public function delete(string $path): void { $this->adapter->delete($path); } public function deleteDirectory(string $path): void { $this->adapter->deleteDirectory($path); } public function createDirectory(string $path, Config $config): void { $this->adapter->createDirectory($path, $config); } public function setVisibility(string $path, string $visibility): void { $this->adapter->setVisibility($path, $visibility); } public function visibility(string $path): FileAttributes { return $this->adapter->visibility($path); } public function mimeType(string $path): FileAttributes { return $this->adapter->mimeType($path); } public function lastModified(string $path): FileAttributes { return $this->adapter->lastModified($path); } public function fileSize(string $path): FileAttributes { return $this->adapter->fileSize($path); } public function listContents(string $path, bool $deep): iterable { return $this->adapter->listContents($path, $deep); } public function move(string $source, string $destination, Config $config): void { $this->adapter->move($source, $destination, $config); } public function copy(string $source, string $destination, Config $config): void { $this->adapter->copy($source, $destination, $config); } }
php
MIT
5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277
2026-01-04T15:02:49.867552Z
false