From f114f887d2a63380468545fc3353d3d1545defa5 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Mon, 20 Nov 2023 14:21:40 +0100 Subject: [PATCH] Refactor to new architecture --- readme.md | 24 +- src/Colors/Profile.php | 4 +- src/Colors/Rgb/Color.php | 2 +- src/Drivers/AbstractFont.php | 30 +- src/Drivers/Gd/Font.php | 8 +- .../Gd/Modifiers/DrawRectangleModifier.php | 16 +- src/Drivers/Imagick/Font.php | 6 +- .../Modifiers/DrawRectangleModifier.php | 8 +- src/EncodedImage.php | 2 +- src/Encoders/AbstractEncoder.php | 15 + src/Encoders/AvifEncoder.php | 11 +- src/Encoders/BmpEncoder.php | 11 +- src/Encoders/GifEncoder.php | 11 +- src/Encoders/JpegEncoder.php | 11 +- src/Encoders/PngEncoder.php | 11 +- src/Encoders/WebpEncoder.php | 11 +- src/{GenericData.php => File.php} | 4 +- src/Interfaces/EncodedImageInterface.php | 2 +- ...ricDataInterface.php => FileInterface.php} | 2 +- src/Interfaces/FontInterface.php | 28 +- src/Modifiers/DrawRectangleModifier.php | 7 +- src/Modifiers/TextWriter.php | 10 +- src/Traits/CanRunCallback.php | 9 +- src/Typography/Line.php | 12 +- src/Typography/TextBlock.php | 10 +- tests/Drivers/Abstract/AbstractImageTest.php | 864 +++++++++--------- tests/Drivers/Gd/FontTest.php | 6 +- tests/Drivers/Gd/ImageTest.php | 284 +++--- tests/Drivers/Imagick/ImageTest.php | 288 +++--- tests/FileTest.php | 47 + tests/Geometry/RectangleResizerTest.php | 4 +- tests/ImageManagerTest.php | 22 +- tests/ImageTest.php | 136 +++ tests/ModifierStackTest.php | 2 +- tests/Traits/CanCreateGdTestImage.php | 24 +- tests/Traits/CanCreateImagickTestImage.php | 9 +- tests/Typography/LineTest.php | 8 +- tests/Typography/TextBlockTest.php | 14 +- 38 files changed, 1060 insertions(+), 913 deletions(-) create mode 100644 src/Encoders/AbstractEncoder.php rename src/{GenericData.php => File.php} (93%) rename src/Interfaces/{GenericDataInterface.php => FileInterface.php} (95%) create mode 100644 tests/FileTest.php create mode 100644 tests/ImageTest.php diff --git a/readme.md b/readme.md index e7591058..ea691ee0 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,18 @@ operations. - Framework-agnostic - PSR-12 compliant +## Installation + +```bash +composer require intervention/image +``` + +## Getting started + +Learn the [basics](https://image.intervention.io/v3/basics/instantiation/) on +how to use Intervention Image and more with the [official +documentation](https://image.intervention.io/v3/). + ## Code Examples ```php @@ -47,18 +59,6 @@ $encoded->save('images/example.jpg'); - GD Library - Imagick PHP extension -## Installation - -```bash -composer require intervention/image -``` - -## Getting started - -Learn the [basics](https://image.intervention.io/v3/basics/instantiation/) on -how to use Intervention Image and more with the [official -documentation](https://image.intervention.io/v3/). - ## Development & Testing With this package comes a Docker image to build a test suite and analysis diff --git a/src/Colors/Profile.php b/src/Colors/Profile.php index 5e94823b..55194f45 100644 --- a/src/Colors/Profile.php +++ b/src/Colors/Profile.php @@ -2,9 +2,9 @@ namespace Intervention\Image\Colors; -use Intervention\Image\GenericData; +use Intervention\Image\File; use Intervention\Image\Interfaces\ProfileInterface; -class Profile extends GenericData implements ProfileInterface +class Profile extends File implements ProfileInterface { } diff --git a/src/Colors/Rgb/Color.php b/src/Colors/Rgb/Color.php index 94bc2c1a..4fc2a9cc 100644 --- a/src/Colors/Rgb/Color.php +++ b/src/Colors/Rgb/Color.php @@ -7,7 +7,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Alpha; use Intervention\Image\Colors\Traits\CanHandleChannels; -use Intervention\Image\Drivers\Abstract\AbstractInputHandler; +use Intervention\Image\Drivers\AbstractInputHandler; use Intervention\Image\Interfaces\ColorChannelInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; diff --git a/src/Drivers/AbstractFont.php b/src/Drivers/AbstractFont.php index feed08cd..4ded595a 100644 --- a/src/Drivers/AbstractFont.php +++ b/src/Drivers/AbstractFont.php @@ -20,38 +20,38 @@ abstract class AbstractFont implements FontInterface protected $valign = 'bottom'; protected $lineHeight = 1.25; - public function size(float $size): FontInterface + public function setSize(float $size): FontInterface { $this->size = $size; return $this; } - public function getSize(): float + public function size(): float { return $this->size; } - public function angle(float $angle): FontInterface + public function setAngle(float $angle): FontInterface { $this->angle = $angle; return $this; } - public function getAngle(): float + public function angle(): float { return $this->angle; } - public function filename(string $filename): FontInterface + public function setFilename(string $filename): FontInterface { $this->filename = $filename; return $this; } - public function getFilename(): ?string + public function filename(): ?string { return $this->filename; } @@ -61,57 +61,57 @@ abstract class AbstractFont implements FontInterface return !is_null($this->filename) && is_file($this->filename); } - public function color($color): FontInterface + public function setColor($color): FontInterface { $this->color = $color; return $this; } - public function getColor(): ColorInterface + public function color(): ColorInterface { return $this->handleInput($this->color); } - public function align(string $align): FontInterface + public function setAlignment(string $align): FontInterface { $this->align = $align; return $this; } - public function getValign(): string + public function valignment(): string { return $this->valign; } - public function valign(string $valign): FontInterface + public function setValignment(string $valign): FontInterface { $this->valign = $valign; return $this; } - public function getAlign(): string + public function alignment(): string { return $this->align; } - public function lineHeight(float $height): FontInterface + public function setLineHeight(float $height): FontInterface { $this->lineHeight = $height; return $this; } - public function getLineHeight(): float + public function lineHeight(): float { return $this->lineHeight; } public function leadingInPixels(): int { - return intval(round($this->fontSizeInPixels() * $this->getLineHeight())); + return intval(round($this->fontSizeInPixels() * $this->lineHeight())); } public function capHeight(): int diff --git a/src/Drivers/Gd/Font.php b/src/Drivers/Gd/Font.php index 68370808..dab733ba 100644 --- a/src/Drivers/Gd/Font.php +++ b/src/Drivers/Gd/Font.php @@ -9,9 +9,9 @@ use Intervention\Image\Geometry\Rectangle; class Font extends AbstractFont { - public function getSize(): float + public function size(): float { - return floatval(ceil(parent::getSize() * 0.75)); + return floatval(ceil(parent::size() * 0.75)); } /** @@ -34,9 +34,9 @@ class Font extends AbstractFont // calculate box size from font file with angle 0 $box = imageftbbox( - $this->getSize(), + $this->size(), 0, - $this->getFilename(), + $this->filename(), $text ); diff --git a/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php b/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php index 5cb332fd..5f8cf207 100644 --- a/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php +++ b/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php @@ -14,10 +14,10 @@ class DrawRectangleModifier extends DrawModifier if ($this->drawable->hasBackgroundColor()) { imagefilledrectangle( $frame->data(), - $this->position->x(), - $this->position->y(), - $this->position->x() + $this->drawable->width(), - $this->position->y() + $this->drawable->height(), + $this->position()->x(), + $this->position()->y(), + $this->position()->x() + $this->drawable->width(), + $this->position()->y() + $this->drawable->height(), $this->driver()->colorToNative( $this->backgroundColor(), $image->colorspace() @@ -30,10 +30,10 @@ class DrawRectangleModifier extends DrawModifier imagesetthickness($frame->data(), $this->drawable->borderSize()); imagerectangle( $frame->data(), - $this->position->x(), - $this->position->y(), - $this->position->x() + $this->drawable->width(), - $this->position->y() + $this->drawable->height(), + $this->position()->x(), + $this->position()->y(), + $this->position()->x() + $this->drawable->width(), + $this->position()->y() + $this->drawable->height(), $this->driver()->colorToNative( $this->borderColor(), $image->colorspace() diff --git a/src/Drivers/Imagick/Font.php b/src/Drivers/Imagick/Font.php index 743f60fe..a2c630bd 100644 --- a/src/Drivers/Imagick/Font.php +++ b/src/Drivers/Imagick/Font.php @@ -24,13 +24,13 @@ class Font extends AbstractFont $draw = new ImagickDraw(); $draw->setStrokeAntialias(true); $draw->setTextAntialias(true); - $draw->setFont($this->getFilename()); - $draw->setFontSize($this->getSize()); + $draw->setFont($this->filename()); + $draw->setFontSize($this->size()); $draw->setTextAlignment(Imagick::ALIGN_LEFT); if ($colorspace) { $draw->setFillColor( - $this->colorToPixel($this->getColor(), $colorspace) + $this->colorToPixel($this->color(), $colorspace) ); } diff --git a/src/Drivers/Imagick/Modifiers/DrawRectangleModifier.php b/src/Drivers/Imagick/Modifiers/DrawRectangleModifier.php index 2a8f7249..c9dfc6c2 100644 --- a/src/Drivers/Imagick/Modifiers/DrawRectangleModifier.php +++ b/src/Drivers/Imagick/Modifiers/DrawRectangleModifier.php @@ -30,10 +30,10 @@ class DrawRectangleModifier extends DrawModifier // build rectangle $drawing->rectangle( - $this->position->x(), - $this->position->y(), - $this->position->x() + $this->drawable->width(), - $this->position->y() + $this->drawable->height() + $this->position()->x(), + $this->position()->y(), + $this->position()->x() + $this->drawable->width(), + $this->position()->y() + $this->drawable->height() ); foreach ($image as $frame) { diff --git a/src/EncodedImage.php b/src/EncodedImage.php index 7f65d455..17f28037 100644 --- a/src/EncodedImage.php +++ b/src/EncodedImage.php @@ -4,7 +4,7 @@ namespace Intervention\Image; use Intervention\Image\Interfaces\EncodedImageInterface; -class EncodedImage extends GenericData implements EncodedImageInterface +class EncodedImage extends File implements EncodedImageInterface { /** * Create new instance diff --git a/src/Encoders/AbstractEncoder.php b/src/Encoders/AbstractEncoder.php new file mode 100644 index 00000000..757fc3ba --- /dev/null +++ b/src/Encoders/AbstractEncoder.php @@ -0,0 +1,15 @@ +encode($this); + } +} diff --git a/src/Encoders/AvifEncoder.php b/src/Encoders/AvifEncoder.php index d7465661..53a9e49b 100644 --- a/src/Encoders/AvifEncoder.php +++ b/src/Encoders/AvifEncoder.php @@ -2,18 +2,9 @@ namespace Intervention\Image\Encoders; -use Intervention\Image\EncodedImage; -use Intervention\Image\Interfaces\EncoderInterface; -use Intervention\Image\Interfaces\ImageInterface; - -class AvifEncoder implements EncoderInterface +class AvifEncoder extends AbstractEncoder { public function __construct(public int $quality = 80) { } - - public function encode(ImageInterface $image): EncodedImage - { - return $image->encode($this); - } } diff --git a/src/Encoders/BmpEncoder.php b/src/Encoders/BmpEncoder.php index d78556a3..6a7b8fb8 100644 --- a/src/Encoders/BmpEncoder.php +++ b/src/Encoders/BmpEncoder.php @@ -2,18 +2,9 @@ namespace Intervention\Image\Encoders; -use Intervention\Image\EncodedImage; -use Intervention\Image\Interfaces\EncoderInterface; -use Intervention\Image\Interfaces\ImageInterface; - -class BmpEncoder implements EncoderInterface +class BmpEncoder extends AbstractEncoder { public function __construct(public int $color_limit = 0) { } - - public function encode(ImageInterface $image): EncodedImage - { - return $image->encode($this); - } } diff --git a/src/Encoders/GifEncoder.php b/src/Encoders/GifEncoder.php index 1aff134e..4894a85e 100644 --- a/src/Encoders/GifEncoder.php +++ b/src/Encoders/GifEncoder.php @@ -2,18 +2,9 @@ namespace Intervention\Image\Encoders; -use Intervention\Image\EncodedImage; -use Intervention\Image\Interfaces\EncoderInterface; -use Intervention\Image\Interfaces\ImageInterface; - -class GifEncoder implements EncoderInterface +class GifEncoder extends AbstractEncoder { public function __construct(public int $color_limit = 0) { } - - public function encode(ImageInterface $image): EncodedImage - { - return $image->encode($this); - } } diff --git a/src/Encoders/JpegEncoder.php b/src/Encoders/JpegEncoder.php index 2ecafb94..bcff36bd 100644 --- a/src/Encoders/JpegEncoder.php +++ b/src/Encoders/JpegEncoder.php @@ -2,18 +2,9 @@ namespace Intervention\Image\Encoders; -use Intervention\Image\EncodedImage; -use Intervention\Image\Interfaces\EncoderInterface; -use Intervention\Image\Interfaces\ImageInterface; - -class JpegEncoder implements EncoderInterface +class JpegEncoder extends AbstractEncoder { public function __construct(public int $quality = 80) { } - - public function encode(ImageInterface $image): EncodedImage - { - return $image->encode($this); - } } diff --git a/src/Encoders/PngEncoder.php b/src/Encoders/PngEncoder.php index efd1d78b..12df34a0 100644 --- a/src/Encoders/PngEncoder.php +++ b/src/Encoders/PngEncoder.php @@ -2,18 +2,9 @@ namespace Intervention\Image\Encoders; -use Intervention\Image\EncodedImage; -use Intervention\Image\Interfaces\EncoderInterface; -use Intervention\Image\Interfaces\ImageInterface; - -class PngEncoder implements EncoderInterface +class PngEncoder extends AbstractEncoder { public function __construct(public int $color_limit = 0) { } - - public function encode(ImageInterface $image): EncodedImage - { - return $image->encode($this); - } } diff --git a/src/Encoders/WebpEncoder.php b/src/Encoders/WebpEncoder.php index 2bed404c..1dbdb473 100644 --- a/src/Encoders/WebpEncoder.php +++ b/src/Encoders/WebpEncoder.php @@ -2,18 +2,9 @@ namespace Intervention\Image\Encoders; -use Intervention\Image\EncodedImage; -use Intervention\Image\Interfaces\EncoderInterface; -use Intervention\Image\Interfaces\ImageInterface; - -class WebpEncoder implements EncoderInterface +class WebpEncoder extends AbstractEncoder { public function __construct(public int $quality = 80) { } - - public function encode(ImageInterface $image): EncodedImage - { - return $image->encode($this); - } } diff --git a/src/GenericData.php b/src/File.php similarity index 93% rename from src/GenericData.php rename to src/File.php index 25381198..892865ce 100644 --- a/src/GenericData.php +++ b/src/File.php @@ -3,10 +3,10 @@ namespace Intervention\Image; use Intervention\Image\Exceptions\NotWritableException; -use Intervention\Image\Interfaces\GenericDataInterface; +use Intervention\Image\Interfaces\FileInterface; use Intervention\Image\Traits\CanBuildFilePointer; -class GenericData implements GenericDataInterface +class File implements FileInterface { use CanBuildFilePointer; diff --git a/src/Interfaces/EncodedImageInterface.php b/src/Interfaces/EncodedImageInterface.php index 6f76540e..0c15f3f7 100644 --- a/src/Interfaces/EncodedImageInterface.php +++ b/src/Interfaces/EncodedImageInterface.php @@ -2,7 +2,7 @@ namespace Intervention\Image\Interfaces; -interface EncodedImageInterface extends GenericDataInterface +interface EncodedImageInterface extends FileInterface { /** * Return Media (MIME) Type of encoded image diff --git a/src/Interfaces/GenericDataInterface.php b/src/Interfaces/FileInterface.php similarity index 95% rename from src/Interfaces/GenericDataInterface.php rename to src/Interfaces/FileInterface.php index 7afc8122..bf3ddbc8 100644 --- a/src/Interfaces/GenericDataInterface.php +++ b/src/Interfaces/FileInterface.php @@ -2,7 +2,7 @@ namespace Intervention\Image\Interfaces; -interface GenericDataInterface +interface FileInterface { /** * Save data in given path in file system diff --git a/src/Interfaces/FontInterface.php b/src/Interfaces/FontInterface.php index efd1b7aa..970c68b9 100644 --- a/src/Interfaces/FontInterface.php +++ b/src/Interfaces/FontInterface.php @@ -7,21 +7,21 @@ use Intervention\Image\Interfaces\ColorInterface; interface FontInterface { - public function color($color): self; - public function getColor(): ColorInterface; - public function size(float $size): self; - public function getSize(): float; - public function angle(float $angle): self; - public function getAngle(): float; - public function filename(string $filename): self; - public function getFilename(): ?string; + public function setColor($color): self; + public function color(): ColorInterface; + public function setSize(float $size): self; + public function size(): float; + public function setAngle(float $angle): self; + public function angle(): float; + public function setFilename(string $filename): self; + public function filename(): ?string; public function hasFilename(): bool; - public function align(string $align): self; - public function getAlign(): string; - public function valign(string $align): self; - public function getValign(): string; - public function lineHeight(float $value): self; - public function getLineHeight(): float; + public function setAlignment(string $align): self; + public function alignment(): string; + public function setValignment(string $align): self; + public function valignment(): string; + public function setLineHeight(float $value): self; + public function lineHeight(): float; public function leadingInPixels(): int; public function fontSizeInPixels(): int; public function capHeight(): int; diff --git a/src/Modifiers/DrawRectangleModifier.php b/src/Modifiers/DrawRectangleModifier.php index c1c40ac0..27be3556 100644 --- a/src/Modifiers/DrawRectangleModifier.php +++ b/src/Modifiers/DrawRectangleModifier.php @@ -3,13 +3,10 @@ namespace Intervention\Image\Modifiers; use Intervention\Image\Geometry\Rectangle; -use Intervention\Image\Interfaces\PointInterface; class DrawRectangleModifier extends AbstractModifier { - public function __construct( - public PointInterface $position, - public Rectangle $drawable, - ) { + public function __construct(public Rectangle $drawable) + { } } diff --git a/src/Modifiers/TextWriter.php b/src/Modifiers/TextWriter.php index 3633c898..41927d3f 100644 --- a/src/Modifiers/TextWriter.php +++ b/src/Modifiers/TextWriter.php @@ -27,7 +27,7 @@ class TextWriter extends AbstractModifier $position = $this->position; $font = $this->font; - $boundingBox = $lines->getBoundingBox($font, $position); + $boundingBox = $lines->boundingBox($font, $position); $pivot = $boundingBox->last(); $leading = $font->leadingInPixels(); @@ -38,11 +38,11 @@ class TextWriter extends AbstractModifier $x_adjustment = 0; foreach ($lines as $line) { - $x_adjustment = $font->getAlign() == 'left' ? 0 : $blockWidth - $line->widthInFont($font); - $x_adjustment = $font->getAlign() == 'right' ? intval(round($x_adjustment)) : $x_adjustment; - $x_adjustment = $font->getAlign() == 'center' ? intval(round($x_adjustment / 2)) : $x_adjustment; + $x_adjustment = $font->alignment() == 'left' ? 0 : $blockWidth - $line->widthInFont($font); + $x_adjustment = $font->alignment() == 'right' ? intval(round($x_adjustment)) : $x_adjustment; + $x_adjustment = $font->alignment() == 'center' ? intval(round($x_adjustment / 2)) : $x_adjustment; $position = new Point($x + $x_adjustment, $y); - $position->rotate($font->getAngle(), $pivot); + $position->rotate($font->angle(), $pivot); $line->setPosition($position); $y += $leading; } diff --git a/src/Traits/CanRunCallback.php b/src/Traits/CanRunCallback.php index 118f69a9..a933e667 100644 --- a/src/Traits/CanRunCallback.php +++ b/src/Traits/CanRunCallback.php @@ -4,6 +4,13 @@ namespace Intervention\Image\Traits; trait CanRunCallback { + protected function runCallback(callable $callback, object $object): object + { + $callback($object); + + return $object; + } + /** * Runs given callback against given object and returns object * @@ -14,7 +21,7 @@ trait CanRunCallback protected function maybeRunCallback(?callable $callback, object $object): object { if (is_callable($callback)) { - $callback($object); + return $this->runCallback($callback, $object); } return $object; diff --git a/src/Typography/Line.php b/src/Typography/Line.php index 10e98665..d8becbe7 100644 --- a/src/Typography/Line.php +++ b/src/Typography/Line.php @@ -4,17 +4,17 @@ namespace Intervention\Image\Typography; use Intervention\Image\Interfaces\FontInterface; use Intervention\Image\Geometry\Point; +use Intervention\Image\Interfaces\PointInterface; class Line { - protected $position; - - public function __construct(protected string $text) - { - $this->position = new Point(); + public function __construct( + protected string $text, + protected PointInterface $position = new Point() + ) { } - public function getPosition(): Point + public function position(): Point { return $this->position; } diff --git a/src/Typography/TextBlock.php b/src/Typography/TextBlock.php index 65e10688..7f7122e8 100644 --- a/src/Typography/TextBlock.php +++ b/src/Typography/TextBlock.php @@ -17,7 +17,7 @@ class TextBlock extends Collection } } - public function getBoundingBox(FontInterface $font, Point $pivot = null): Polygon + public function boundingBox(FontInterface $font, Point $pivot = null): Polygon { $pivot = $pivot ? $pivot : new Point(); @@ -31,10 +31,10 @@ class TextBlock extends Collection $box->setPivot($pivot); // align - $box->align($font->getAlign()); - $box->valign($font->getValign()); + $box->align($font->alignment()); + $box->valign($font->valignment()); - $box->rotate($font->getAngle()); + $box->rotate($font->angle()); return $box; } @@ -49,7 +49,7 @@ class TextBlock extends Collection return $this->items; } - public function getLine($key): ?Line + public function line($key): ?Line { if (!array_key_exists($key, $this->lines())) { return null; diff --git a/tests/Drivers/Abstract/AbstractImageTest.php b/tests/Drivers/Abstract/AbstractImageTest.php index 44f6f1e3..d790c29e 100644 --- a/tests/Drivers/Abstract/AbstractImageTest.php +++ b/tests/Drivers/Abstract/AbstractImageTest.php @@ -17,435 +17,435 @@ use Mockery; /** * @covers \Intervention\Image\Drivers\Abstract\AbstractImage */ -class AbstractImageTest extends TestCase -{ - protected function abstractImageMock(): AbstractImage - { - $frame1 = Mockery::mock(FrameInterface::class); - $frame1->shouldReceive('ident')->andReturn(1); - $frame2 = Mockery::mock(FrameInterface::class); - $frame2->shouldReceive('ident')->andReturn(2); - $frame3 = Mockery::mock(FrameInterface::class); - $frame3->shouldReceive('ident')->andReturn(3); - - $collection = new Collection([$frame1, $frame2, $frame3]); - - $mock = Mockery::mock(AbstractImage::class, ImageInterface::class) - ->shouldAllowMockingProtectedMethods() - ->makePartial(); - - $mock->shouldReceive('width')->andReturn(300); - $mock->shouldReceive('height')->andReturn(200); - $mock->shouldReceive('getIterator')->andReturn($collection); - - return $mock; - } - - public function testGetSize(): void - { - $img = $this->abstractImageMock(); - $this->assertInstanceOf(Rectangle::class, $img->size()); - $this->assertEquals(300, $img->size()->width()); - $this->assertEquals(200, $img->size()->height()); - } - - public function testSizeAlias(): void - { - $img = $this->abstractImageMock(); - $this->assertInstanceOf(Rectangle::class, $img->size()); - $this->assertEquals(300, $img->size()->width()); - $this->assertEquals(200, $img->size()->height()); - } - - public function testModify(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - $result = $img->modify($modifier); - $this->assertInstanceOf(ImageInterface::class, $img); - } - - public function testEncode(): void - { - $img = $this->abstractImageMock(); - - $encoder = Mockery::mock(EncoderInterface::class); - $encoded = Mockery::mock(EncodedImage::class); - $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); - $result = $img->encode($encoder); - $this->assertInstanceOf(ImageInterface::class, $img); - } - - public function testToJpeg(): void - { - $img = $this->abstractImageMock(); - - $encoded = Mockery::mock(EncodedImage::class); - $encoder = Mockery::mock(EncoderInterface::class); - $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); - - $img->shouldReceive('resolveDriverClass') - ->with('Encoders\JpegEncoder', 45) - ->andReturn($encoder); - - $result = $img->toJpeg(45); - $this->assertInstanceOf(EncodedImage::class, $result); - } - - public function testToWebp(): void - { - $img = $this->abstractImageMock(); - - $encoded = Mockery::mock(EncodedImage::class); - $encoder = Mockery::mock(EncoderInterface::class); - $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); - - $img->shouldReceive('resolveDriverClass') - ->with('Encoders\WebpEncoder', 45) - ->andReturn($encoder); - - $result = $img->toWebp(45); - $this->assertInstanceOf(EncodedImage::class, $result); - } - - public function testToGif(): void - { - $img = $this->abstractImageMock(); - - $encoded = Mockery::mock(EncodedImage::class); - $encoder = Mockery::mock(EncoderInterface::class); - $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); - - $img->shouldReceive('resolveDriverClass') - ->with('Encoders\GifEncoder', 0) - ->andReturn($encoder); - - $result = $img->toGif(); - $this->assertInstanceOf(EncodedImage::class, $result); - } - - public function testToPng(): void - { - $img = $this->abstractImageMock(); - - $encoded = Mockery::mock(EncodedImage::class); - $encoder = Mockery::mock(EncoderInterface::class); - $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); - - $img->shouldReceive('resolveDriverClass') - ->with('Encoders\PngEncoder', 0) - ->andReturn($encoder); - - $result = $img->toPng(); - $this->assertInstanceOf(EncodedImage::class, $result); - } - - public function testGreyscale(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\GreyscaleModifier') - ->andReturn($modifier); - - $result = $img->greyscale(); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testInvert(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\InvertModifier') - ->andReturn($modifier); - - $result = $img->invert(); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testBrightness(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\BrightnessModifier', 5) - ->andReturn($modifier); - - $result = $img->brightness(5); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testContrast(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\ContrastModifier', 5) - ->andReturn($modifier); - - $result = $img->contrast(5); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testBlur(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\BlurModifier', 3) - ->andReturn($modifier); - - $result = $img->blur(3); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testRotate(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\RotateModifier', 3, 'cccccc') - ->andReturn($modifier); - - $result = $img->rotate(3, 'cccccc'); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testPlace(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0) - ->andReturn($modifier); - - $result = $img->place('el', 'top-left', 0, 0); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testFill(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $color = Mockery::mock(ColorInterface::class); - - $img->shouldReceive('handleInput') - ->with('abcdef') - ->andReturn($color); - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\FillModifier', $color, null) - ->andReturn($modifier); - - $result = $img->fill('abcdef'); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testPixelate(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\PixelateModifier', 42) - ->andReturn($modifier); - - $result = $img->pixelate(42); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testSharpen(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\SharpenModifier', 7) - ->andReturn($modifier); - - $result = $img->sharpen(7); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testPickColors(): void - { - $color = Mockery::mock(ColorInterface::class); - $img = $this->abstractImageMock(); - $img->shouldReceive('pickColor')->times(3)->andReturn($color); - $result = $img->pickColors(1, 2); - $this->assertInstanceOf(Collection::class, $result); - } - - public function testResize(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\ResizeModifier', 200, 100) - ->andReturn($modifier); - - $result = $img->resize(200, 100); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testResizeDown(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\ResizeDownModifier', 200, 100) - ->andReturn($modifier); - - $result = $img->resizeDown(200, 100); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testScale(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\ScaleModifier', 200, 100) - ->andReturn($modifier); - - $result = $img->scale(200, 100); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testScaleDown(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\ScaleDownModifier', 200, 100) - ->andReturn($modifier); - - $result = $img->scaleDown(200, 100); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testFit(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\FitModifier', 200, 100, 'center') - ->andReturn($modifier); - - $result = $img->fit(200, 100, 'center'); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testFitDown(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\FitDownModifier', 200, 100, 'center') - ->andReturn($modifier); - - $result = $img->fitDown(200, 100, 'center'); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testPad(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center') - ->andReturn($modifier); - - $result = $img->pad(200, 100, 'ffffff', 'center'); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testPadDown(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center') - ->andReturn($modifier); - - $result = $img->padDown(200, 100, 'ffffff', 'center'); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testSetGetExif(): void - { - $img = $this->abstractImageMock(); - $img->setExif((['test' => 'value'])); - - $this->assertInstanceOf(Collection::class, $img->exif()); - $this->assertEquals('value', $img->exif('test')); - } - - public function testDestroy(): void - { - $img = $this->abstractImageMock(); - - $modifier = Mockery::mock(ModifierInterface::class); - $modifier->shouldReceive('apply')->with($img)->andReturn($img); - - $img->shouldReceive('resolveDriverClass') - ->with('Modifiers\DestroyModifier') - ->andReturn($modifier); - - $img->destroy(); - } -} +// class AbstractImageTest extends TestCase +// { +// protected function abstractImageMock(): AbstractImage +// { +// $frame1 = Mockery::mock(FrameInterface::class); +// $frame1->shouldReceive('ident')->andReturn(1); +// $frame2 = Mockery::mock(FrameInterface::class); +// $frame2->shouldReceive('ident')->andReturn(2); +// $frame3 = Mockery::mock(FrameInterface::class); +// $frame3->shouldReceive('ident')->andReturn(3); +// +// $collection = new Collection([$frame1, $frame2, $frame3]); +// +// $mock = Mockery::mock(AbstractImage::class, ImageInterface::class) +// ->shouldAllowMockingProtectedMethods() +// ->makePartial(); +// +// $mock->shouldReceive('width')->andReturn(300); +// $mock->shouldReceive('height')->andReturn(200); +// $mock->shouldReceive('getIterator')->andReturn($collection); +// +// return $mock; +// } +// +// public function testGetSize(): void +// { +// $img = $this->abstractImageMock(); +// $this->assertInstanceOf(Rectangle::class, $img->size()); +// $this->assertEquals(300, $img->size()->width()); +// $this->assertEquals(200, $img->size()->height()); +// } +// +// public function testSizeAlias(): void +// { +// $img = $this->abstractImageMock(); +// $this->assertInstanceOf(Rectangle::class, $img->size()); +// $this->assertEquals(300, $img->size()->width()); +// $this->assertEquals(200, $img->size()->height()); +// } +// +// public function testModify(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// $result = $img->modify($modifier); +// $this->assertInstanceOf(ImageInterface::class, $img); +// } +// +// public function testEncode(): void +// { +// $img = $this->abstractImageMock(); +// +// $encoder = Mockery::mock(EncoderInterface::class); +// $encoded = Mockery::mock(EncodedImage::class); +// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); +// $result = $img->encode($encoder); +// $this->assertInstanceOf(ImageInterface::class, $img); +// } +// +// public function testToJpeg(): void +// { +// $img = $this->abstractImageMock(); +// +// $encoded = Mockery::mock(EncodedImage::class); +// $encoder = Mockery::mock(EncoderInterface::class); +// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Encoders\JpegEncoder', 45) +// ->andReturn($encoder); +// +// $result = $img->toJpeg(45); +// $this->assertInstanceOf(EncodedImage::class, $result); +// } +// +// public function testToWebp(): void +// { +// $img = $this->abstractImageMock(); +// +// $encoded = Mockery::mock(EncodedImage::class); +// $encoder = Mockery::mock(EncoderInterface::class); +// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Encoders\WebpEncoder', 45) +// ->andReturn($encoder); +// +// $result = $img->toWebp(45); +// $this->assertInstanceOf(EncodedImage::class, $result); +// } +// +// public function testToGif(): void +// { +// $img = $this->abstractImageMock(); +// +// $encoded = Mockery::mock(EncodedImage::class); +// $encoder = Mockery::mock(EncoderInterface::class); +// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Encoders\GifEncoder', 0) +// ->andReturn($encoder); +// +// $result = $img->toGif(); +// $this->assertInstanceOf(EncodedImage::class, $result); +// } +// +// public function testToPng(): void +// { +// $img = $this->abstractImageMock(); +// +// $encoded = Mockery::mock(EncodedImage::class); +// $encoder = Mockery::mock(EncoderInterface::class); +// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Encoders\PngEncoder', 0) +// ->andReturn($encoder); +// +// $result = $img->toPng(); +// $this->assertInstanceOf(EncodedImage::class, $result); +// } +// +// public function testGreyscale(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\GreyscaleModifier') +// ->andReturn($modifier); +// +// $result = $img->greyscale(); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testInvert(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\InvertModifier') +// ->andReturn($modifier); +// +// $result = $img->invert(); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testBrightness(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\BrightnessModifier', 5) +// ->andReturn($modifier); +// +// $result = $img->brightness(5); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testContrast(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\ContrastModifier', 5) +// ->andReturn($modifier); +// +// $result = $img->contrast(5); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testBlur(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\BlurModifier', 3) +// ->andReturn($modifier); +// +// $result = $img->blur(3); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testRotate(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\RotateModifier', 3, 'cccccc') +// ->andReturn($modifier); +// +// $result = $img->rotate(3, 'cccccc'); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testPlace(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0) +// ->andReturn($modifier); +// +// $result = $img->place('el', 'top-left', 0, 0); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testFill(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $color = Mockery::mock(ColorInterface::class); +// +// $img->shouldReceive('handleInput') +// ->with('abcdef') +// ->andReturn($color); +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\FillModifier', $color, null) +// ->andReturn($modifier); +// +// $result = $img->fill('abcdef'); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testPixelate(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\PixelateModifier', 42) +// ->andReturn($modifier); +// +// $result = $img->pixelate(42); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testSharpen(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\SharpenModifier', 7) +// ->andReturn($modifier); +// +// $result = $img->sharpen(7); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testPickColors(): void +// { +// $color = Mockery::mock(ColorInterface::class); +// $img = $this->abstractImageMock(); +// $img->shouldReceive('pickColor')->times(3)->andReturn($color); +// $result = $img->pickColors(1, 2); +// $this->assertInstanceOf(Collection::class, $result); +// } +// +// public function testResize(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\ResizeModifier', 200, 100) +// ->andReturn($modifier); +// +// $result = $img->resize(200, 100); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testResizeDown(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\ResizeDownModifier', 200, 100) +// ->andReturn($modifier); +// +// $result = $img->resizeDown(200, 100); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testScale(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\ScaleModifier', 200, 100) +// ->andReturn($modifier); +// +// $result = $img->scale(200, 100); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testScaleDown(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\ScaleDownModifier', 200, 100) +// ->andReturn($modifier); +// +// $result = $img->scaleDown(200, 100); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testFit(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\FitModifier', 200, 100, 'center') +// ->andReturn($modifier); +// +// $result = $img->fit(200, 100, 'center'); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testFitDown(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\FitDownModifier', 200, 100, 'center') +// ->andReturn($modifier); +// +// $result = $img->fitDown(200, 100, 'center'); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testPad(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center') +// ->andReturn($modifier); +// +// $result = $img->pad(200, 100, 'ffffff', 'center'); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testPadDown(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center') +// ->andReturn($modifier); +// +// $result = $img->padDown(200, 100, 'ffffff', 'center'); +// $this->assertInstanceOf(ImageInterface::class, $result); +// } +// +// public function testSetGetExif(): void +// { +// $img = $this->abstractImageMock(); +// $img->setExif((['test' => 'value'])); +// +// $this->assertInstanceOf(Collection::class, $img->exif()); +// $this->assertEquals('value', $img->exif('test')); +// } +// +// public function testDestroy(): void +// { +// $img = $this->abstractImageMock(); +// +// $modifier = Mockery::mock(ModifierInterface::class); +// $modifier->shouldReceive('apply')->with($img)->andReturn($img); +// +// $img->shouldReceive('resolveDriverClass') +// ->with('Modifiers\DestroyModifier') +// ->andReturn($modifier); +// +// $img->destroy(); +// } +// } diff --git a/tests/Drivers/Gd/FontTest.php b/tests/Drivers/Gd/FontTest.php index 62e02e48..064e51f6 100644 --- a/tests/Drivers/Gd/FontTest.php +++ b/tests/Drivers/Gd/FontTest.php @@ -10,15 +10,15 @@ class FontTest extends TestCase public function testGetSize(): void { $font = new Font(); - $font->size(12); - $this->assertEquals(9, $font->getSize()); + $font->setSize(12); + $this->assertEquals(9, $font->size()); } public function testGetGdFont(): void { $font = new Font(); $this->assertEquals(1, $font->getGdFont()); - $font->filename(12); + $font->setFilename(12); $this->assertEquals(12, $font->getGdFont()); } diff --git a/tests/Drivers/Gd/ImageTest.php b/tests/Drivers/Gd/ImageTest.php index 1fe99d2a..db2c70b7 100644 --- a/tests/Drivers/Gd/ImageTest.php +++ b/tests/Drivers/Gd/ImageTest.php @@ -18,145 +18,145 @@ use Intervention\Image\Resolution; * @requires extension gd * @covers \Intervention\Image\Drivers\Gd\Image */ -class ImageTest extends TestCase -{ - protected Image $image; - - protected function setUp(): void - { - $gd1 = imagecreatetruecolor(3, 2); - imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0)); - $gd2 = imagecreatetruecolor(3, 2); - imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0)); - $gd3 = imagecreatetruecolor(3, 2); - imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255)); - $this->image = new Image(new Collection([ - new Frame($gd1), - new Frame($gd2), - new Frame($gd3), - ])); - } - - public function testConstructor(): void - { - $this->assertInstanceOf(Image::class, $this->image); - } - - public function testCount(): void - { - $this->assertEquals(3, $this->image->count()); - $this->assertEquals(3, count($this->image)); - } - - public function testIterator(): void - { - foreach ($this->image as $frame) { - $this->assertInstanceOf(Frame::class, $frame); - } - } - - public function testGetFrame(): void - { - $this->assertInstanceOf(Frame::class, $this->image->frame()); - $this->assertInstanceOf(Frame::class, $this->image->frame(1)); - } - - public function testAddFrame(): void - { - $this->assertCount(3, $this->image); - $result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2))); - $this->assertInstanceOf(Image::class, $result); - $this->assertCount(4, $this->image); - } - - public function testSetGetLoops(): void - { - $this->assertEquals(0, $this->image->loops()); - $result = $this->image->setLoops(12); - $this->assertEquals(12, $this->image->loops()); - $this->assertInstanceOf(Image::class, $result); - } - - public function testIsAnimated(): void - { - $this->assertTrue($this->image->isAnimated()); - } - - public function testWidth(): void - { - $this->assertEquals(3, $this->image->width()); - } - - public function testHeight(): void - { - $this->assertEquals(2, $this->image->height()); - } - - public function testGetSize(): void - { - $this->assertInstanceOf(Rectangle::class, $this->image->size()); - } - - public function testPickColor(): void - { - $color = $this->image->pickColor(0, 0); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([255, 0, 0, 255], $color->toArray()); - - $color = $this->image->pickColor(0, 0, 1); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([0, 255, 0, 255], $color->toArray()); - - $color = $this->image->pickColor(0, 0, 2); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([0, 0, 255, 255], $color->toArray()); - - $this->expectException(AnimationException::class); - $this->image->pickColor(0, 0, 3); - } - - public function testPickColors(): void - { - $colors = $this->image->pickColors(0, 0); - $this->assertInstanceOf(Collection::class, $colors); - $this->assertCount(3, $colors); - $this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray()); - $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray()); - $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray()); - } - - public function testGetColorspace(): void - { - $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace()); - } - - public function testSetColorspace(): void - { - $result = $this->image->setColorspace('rgb'); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace(RgbColorspace::class); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace(new RgbColorspace()); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); - - $this->expectException(NotSupportedException::class); - $this->image->setColorspace('cmyk'); - - $this->expectException(NotSupportedException::class); - $this->image->setColorspace(CmykColorspace::class); - - $this->expectException(NotSupportedException::class); - $this->image->setColorspace(new CmykColorspace()); - } - - public function testResolution(): void - { - $result = $this->image->resolution(); - $this->assertInstanceOf(Resolution::class, $result); - } -} +// class ImageTest extends TestCase +// { +// protected Image $image; +// +// protected function setUp(): void +// { +// $gd1 = imagecreatetruecolor(3, 2); +// imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0)); +// $gd2 = imagecreatetruecolor(3, 2); +// imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0)); +// $gd3 = imagecreatetruecolor(3, 2); +// imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255)); +// $this->image = new Image(new Collection([ +// new Frame($gd1), +// new Frame($gd2), +// new Frame($gd3), +// ])); +// } +// +// public function testConstructor(): void +// { +// $this->assertInstanceOf(Image::class, $this->image); +// } +// +// public function testCount(): void +// { +// $this->assertEquals(3, $this->image->count()); +// $this->assertEquals(3, count($this->image)); +// } +// +// public function testIterator(): void +// { +// foreach ($this->image as $frame) { +// $this->assertInstanceOf(Frame::class, $frame); +// } +// } +// +// public function testGetFrame(): void +// { +// $this->assertInstanceOf(Frame::class, $this->image->frame()); +// $this->assertInstanceOf(Frame::class, $this->image->frame(1)); +// } +// +// public function testAddFrame(): void +// { +// $this->assertCount(3, $this->image); +// $result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2))); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertCount(4, $this->image); +// } +// +// public function testSetGetLoops(): void +// { +// $this->assertEquals(0, $this->image->loops()); +// $result = $this->image->setLoops(12); +// $this->assertEquals(12, $this->image->loops()); +// $this->assertInstanceOf(Image::class, $result); +// } +// +// public function testIsAnimated(): void +// { +// $this->assertTrue($this->image->isAnimated()); +// } +// +// public function testWidth(): void +// { +// $this->assertEquals(3, $this->image->width()); +// } +// +// public function testHeight(): void +// { +// $this->assertEquals(2, $this->image->height()); +// } +// +// public function testGetSize(): void +// { +// $this->assertInstanceOf(Rectangle::class, $this->image->size()); +// } +// +// public function testPickColor(): void +// { +// $color = $this->image->pickColor(0, 0); +// $this->assertInstanceOf(Color::class, $color); +// $this->assertEquals([255, 0, 0, 255], $color->toArray()); +// +// $color = $this->image->pickColor(0, 0, 1); +// $this->assertInstanceOf(Color::class, $color); +// $this->assertEquals([0, 255, 0, 255], $color->toArray()); +// +// $color = $this->image->pickColor(0, 0, 2); +// $this->assertInstanceOf(Color::class, $color); +// $this->assertEquals([0, 0, 255, 255], $color->toArray()); +// +// $this->expectException(AnimationException::class); +// $this->image->pickColor(0, 0, 3); +// } +// +// public function testPickColors(): void +// { +// $colors = $this->image->pickColors(0, 0); +// $this->assertInstanceOf(Collection::class, $colors); +// $this->assertCount(3, $colors); +// $this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray()); +// $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray()); +// $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray()); +// } +// +// public function testGetColorspace(): void +// { +// $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace()); +// } +// +// public function testSetColorspace(): void +// { +// $result = $this->image->setColorspace('rgb'); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace(RgbColorspace::class); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace(new RgbColorspace()); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); +// +// $this->expectException(NotSupportedException::class); +// $this->image->setColorspace('cmyk'); +// +// $this->expectException(NotSupportedException::class); +// $this->image->setColorspace(CmykColorspace::class); +// +// $this->expectException(NotSupportedException::class); +// $this->image->setColorspace(new CmykColorspace()); +// } +// +// public function testResolution(): void +// { +// $result = $this->image->resolution(); +// $this->assertInstanceOf(Resolution::class, $result); +// } +// } diff --git a/tests/Drivers/Imagick/ImageTest.php b/tests/Drivers/Imagick/ImageTest.php index 4f0a5b09..4adeb0dd 100644 --- a/tests/Drivers/Imagick/ImageTest.php +++ b/tests/Drivers/Imagick/ImageTest.php @@ -19,147 +19,147 @@ use Intervention\Image\Tests\TestCase; * @requires extension imagick * @covers \Intervention\Image\Drivers\Imagick\Image */ -class ImageTest extends TestCase -{ - protected Image $image; - - protected function setUp(): void - { - // create base image - $imagick = new Imagick(); - - // add frame - $frame = new Imagick(); - $frame->newImage(3, 2, new ImagickPixel('red'), 'png'); - $imagick->addImage($frame); - - // add frame - $frame = new Imagick(); - $frame->newImage(3, 2, new ImagickPixel('green'), 'png'); - $imagick->addImage($frame); - - // create intervention image - $this->image = new Image($imagick); - } - - public function testConstructor(): void - { - $this->assertInstanceOf(Image::class, $this->image); - } - - public function testGetFrame(): void - { - $this->assertInstanceOf(Frame::class, $this->image->frame()); - $this->assertInstanceOf(Frame::class, $this->image->frame(1)); - $this->expectException(AnimationException::class); - $this->image->frame(2); - } - - public function testAddFrame(): void - { - $frame = new Imagick(); - $frame->newImage(3, 2, new ImagickPixel('blue'), 'png'); - $frame = new Frame($frame); - - $this->assertCount(2, $this->image); - $result = $this->image->addFrame($frame); - $this->assertInstanceOf(Image::class, $result); - $this->assertCount(3, $this->image); - } - - public function testIterator(): void - { - foreach ($this->image as $frame) { - $this->assertInstanceOf(Frame::class, $frame); - } - } - - public function testCount(): void - { - $this->assertEquals(2, $this->image->count()); - $this->assertEquals(2, count($this->image)); - } - - public function testWidth(): void - { - $this->assertEquals(3, $this->image->width()); - } - - public function testHeight(): void - { - $this->assertEquals(2, $this->image->height()); - } - - public function testGetSize(): void - { - $this->assertInstanceOf(Rectangle::class, $this->image->size()); - } - - public function testGetColorspace(): void - { - $imagick = new Imagick(); - $imagick->readImageBlob($this->getTestImageData('test.jpg')); - $image = new Image($imagick); - $this->assertInstanceOf(RgbColorspace::class, $image->colorspace()); - - $imagick = new Imagick(); - $imagick->readImageBlob($this->getTestImageData('cmyk.jpg')); - $image = new Image($imagick); - $this->assertInstanceOf(CmykColorspace::class, $image->colorspace()); - } - - public function testSetColorspace(): void - { - $result = $this->image->setColorspace('rgb'); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace(RgbColorspace::class); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace(new RgbColorspace()); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace('cmyk'); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace(CmykColorspace::class); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); - - $result = $this->image->setColorspace(new CmykColorspace()); - $this->assertInstanceOf(Image::class, $result); - $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); - } - - public function testSetGetProfile(): void - { - $imagick = new Imagick(); - $imagick->readImageBlob($this->getTestImageData('test.jpg')); - $image = new Image($imagick); - $result = $image->profile(); - $this->assertInstanceOf(Profile::class, $result); - $result = $image->setProfile($result); - $this->assertInstanceOf(Image::class, $result); - } - - public function testRemoveProfile(): void - { - $imagick = new Imagick(); - $imagick->readImageBlob($this->getTestImageData('test.jpg')); - $image = new Image($imagick); - $result = $image->removeProfile(); - $this->assertInstanceOf(Image::class, $result); - $this->expectException(ColorException::class); - $image->profile(); - } - - public function testResolution(): void - { - $result = $this->image->resolution(); - $this->assertInstanceOf(Resolution::class, $result); - } -} +// class ImageTest extends TestCase +// { +// protected Image $image; +// +// protected function setUp(): void +// { +// // create base image +// $imagick = new Imagick(); +// +// // add frame +// $frame = new Imagick(); +// $frame->newImage(3, 2, new ImagickPixel('red'), 'png'); +// $imagick->addImage($frame); +// +// // add frame +// $frame = new Imagick(); +// $frame->newImage(3, 2, new ImagickPixel('green'), 'png'); +// $imagick->addImage($frame); +// +// // create intervention image +// $this->image = new Image($imagick); +// } +// +// public function testConstructor(): void +// { +// $this->assertInstanceOf(Image::class, $this->image); +// } +// +// public function testGetFrame(): void +// { +// $this->assertInstanceOf(Frame::class, $this->image->frame()); +// $this->assertInstanceOf(Frame::class, $this->image->frame(1)); +// $this->expectException(AnimationException::class); +// $this->image->frame(2); +// } +// +// public function testAddFrame(): void +// { +// $frame = new Imagick(); +// $frame->newImage(3, 2, new ImagickPixel('blue'), 'png'); +// $frame = new Frame($frame); +// +// $this->assertCount(2, $this->image); +// $result = $this->image->addFrame($frame); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertCount(3, $this->image); +// } +// +// public function testIterator(): void +// { +// foreach ($this->image as $frame) { +// $this->assertInstanceOf(Frame::class, $frame); +// } +// } +// +// public function testCount(): void +// { +// $this->assertEquals(2, $this->image->count()); +// $this->assertEquals(2, count($this->image)); +// } +// +// public function testWidth(): void +// { +// $this->assertEquals(3, $this->image->width()); +// } +// +// public function testHeight(): void +// { +// $this->assertEquals(2, $this->image->height()); +// } +// +// public function testGetSize(): void +// { +// $this->assertInstanceOf(Rectangle::class, $this->image->size()); +// } +// +// public function testGetColorspace(): void +// { +// $imagick = new Imagick(); +// $imagick->readImageBlob($this->getTestImageData('test.jpg')); +// $image = new Image($imagick); +// $this->assertInstanceOf(RgbColorspace::class, $image->colorspace()); +// +// $imagick = new Imagick(); +// $imagick->readImageBlob($this->getTestImageData('cmyk.jpg')); +// $image = new Image($imagick); +// $this->assertInstanceOf(CmykColorspace::class, $image->colorspace()); +// } +// +// public function testSetColorspace(): void +// { +// $result = $this->image->setColorspace('rgb'); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace(RgbColorspace::class); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace(new RgbColorspace()); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace('cmyk'); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace(CmykColorspace::class); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); +// +// $result = $this->image->setColorspace(new CmykColorspace()); +// $this->assertInstanceOf(Image::class, $result); +// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); +// } +// +// public function testSetGetProfile(): void +// { +// $imagick = new Imagick(); +// $imagick->readImageBlob($this->getTestImageData('test.jpg')); +// $image = new Image($imagick); +// $result = $image->profile(); +// $this->assertInstanceOf(Profile::class, $result); +// $result = $image->setProfile($result); +// $this->assertInstanceOf(Image::class, $result); +// } +// +// public function testRemoveProfile(): void +// { +// $imagick = new Imagick(); +// $imagick->readImageBlob($this->getTestImageData('test.jpg')); +// $image = new Image($imagick); +// $result = $image->removeProfile(); +// $this->assertInstanceOf(Image::class, $result); +// $this->expectException(ColorException::class); +// $image->profile(); +// } +// +// public function testResolution(): void +// { +// $result = $this->image->resolution(); +// $this->assertInstanceOf(Resolution::class, $result); +// } +// } diff --git a/tests/FileTest.php b/tests/FileTest.php new file mode 100644 index 00000000..86e8b7d6 --- /dev/null +++ b/tests/FileTest.php @@ -0,0 +1,47 @@ +assertInstanceOf(File::class, $file); + } + + public function testSave(): void + { + $filename = __DIR__ . '/file_' . strval(hrtime(true)) . '.test'; + $file = new File('foo'); + $file->save($filename); + $this->assertTrue(file_exists($filename)); + unlink($filename); + } + + public function testToString(): void + { + $file = new File('foo'); + $string = $file->toString(); + $this->assertEquals('foo', $string); + $this->assertEquals('foo', (string) $string); + } + + public function testToFilePointer(): void + { + $file = new File('foo'); + $fp = $file->toFilePointer(); + $this->assertIsResource($fp); + } + + public function testSize(): void + { + $file = new File('foo'); + $this->assertEquals(3, $file->size()); + } +} diff --git a/tests/Geometry/RectangleResizerTest.php b/tests/Geometry/RectangleResizerTest.php index 503afe64..bcc569b4 100644 --- a/tests/Geometry/RectangleResizerTest.php +++ b/tests/Geometry/RectangleResizerTest.php @@ -429,8 +429,8 @@ class RectangleResizerTest extends TestCase $resized = $resizer->crop($origin, $position); $this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->height(), $resized->height()); - $this->assertEquals($result->getPivot()->x(), $resized->pivot()->x()); - $this->assertEquals($result->getPivot()->y(), $resized->pivot()->y()); + $this->assertEquals($result->pivot()->x(), $resized->pivot()->x()); + $this->assertEquals($result->pivot()->y(), $resized->pivot()->y()); } public function cropDataProvider(): array diff --git a/tests/ImageManagerTest.php b/tests/ImageManagerTest.php index aafecad3..5094a504 100644 --- a/tests/ImageManagerTest.php +++ b/tests/ImageManagerTest.php @@ -2,7 +2,8 @@ namespace Intervention\Image\Tests; -use Intervention\Image\Exceptions\ConfigurationException; +use Intervention\Image\Drivers\Gd\Driver as GdDriver; +use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; @@ -13,16 +14,19 @@ class ImageManagerTest extends TestCase { public function testConstructor() { - $manager = new ImageManager(driver: 'gd'); + $manager = new ImageManager(new GdDriver()); $this->assertInstanceOf(ImageManager::class, $manager); - $this->expectException(ConfigurationException::class); - $manager = new ImageManager('foo'); + $manager = new ImageManager(GdDriver::class); + $this->assertInstanceOf(ImageManager::class, $manager); } public function testWithDriver(): void { - $manager = ImageManager::withDriver('gd'); + $manager = ImageManager::withDriver(new GdDriver()); + $this->assertInstanceOf(ImageManager::class, $manager); + + $manager = ImageManager::withDriver(GdDriver::class); $this->assertInstanceOf(ImageManager::class, $manager); } @@ -38,7 +42,7 @@ class ImageManagerTest extends TestCase /** @requires extension gd */ public function testCreateGd() { - $manager = new ImageManager('gd'); + $manager = new ImageManager(GdDriver::class); $image = $manager->create(5, 4); $this->assertInstanceOf(ImageInterface::class, $image); } @@ -46,7 +50,7 @@ class ImageManagerTest extends TestCase /** @requires extension gd */ public function testReadGd() { - $manager = new ImageManager('gd'); + $manager = new ImageManager(GdDriver::class); $image = $manager->read(__DIR__ . '/images/red.gif'); $this->assertInstanceOf(ImageInterface::class, $image); } @@ -54,7 +58,7 @@ class ImageManagerTest extends TestCase /** @requires extension imagick */ public function testCreateImagick() { - $manager = new ImageManager('imagick'); + $manager = new ImageManager(ImagickDriver::class); $image = $manager->create(5, 4); $this->assertInstanceOf(ImageInterface::class, $image); } @@ -62,7 +66,7 @@ class ImageManagerTest extends TestCase /** @requires extension imagick */ public function testReadImagick() { - $manager = new ImageManager('imagick'); + $manager = new ImageManager(ImagickDriver::class); $image = $manager->read(__DIR__ . '/images/red.gif'); $this->assertInstanceOf(ImageInterface::class, $image); } diff --git a/tests/ImageTest.php b/tests/ImageTest.php new file mode 100644 index 00000000..52eb522a --- /dev/null +++ b/tests/ImageTest.php @@ -0,0 +1,136 @@ +shouldReceive('apply')->andReturn( + Mockery::mock(ImageInterface::class) + ); + + $encoder = Mockery::mock(EncoderInterface::class); + $encoder->shouldReceive('encode')->andReturn( + new EncodedImage('foo') + ); + + $this->encoder_mock = $encoder; + $this->modifier_mock = $modifier; + } + + private function testImage(): Image + { + $core = Mockery::mock(CoreInterface::class); + $core->shouldReceive('width')->andReturn(300); + $core->shouldReceive('height')->andReturn(200); + $core->shouldReceive('count')->andReturn(12); + $core->shouldReceive('loops')->andReturn(12); + $core->shouldReceive('colorspace')->andReturn(new Colorspace()); + $core->shouldReceive('resolve')->andReturn(new GreyscaleModifier()); + + $driver = Mockery::mock(DriverInterface::class); + $driver->shouldReceive('resolve')->with($this->modifier_mock)->andReturn($this->modifier_mock); + $driver->shouldReceive('resolve')->with($this->encoder_mock)->andReturn($this->encoder_mock); + + $exif = Mockery::mock(CollectionInterface::class); + + return new Image($driver, $core, $exif); + } + + public function testConstructor(): void + { + $image = $this->testImage(); + $this->assertInstanceOf(Image::class, $image); + } + + public function testDriver(): void + { + $image = $this->testImage(); + $this->assertInstanceOf(DriverInterface::class, $image->driver()); + } + + public function testCore(): void + { + $image = $this->testImage(); + $this->assertInstanceOf(CoreInterface::class, $image->core()); + } + + public function testWidthHeightSize(): void + { + $image = $this->testImage(); + $this->assertEquals(300, $image->width()); + $this->assertEquals(200, $image->height()); + $this->assertInstanceOf(SizeInterface::class, $image->size()); + $this->assertEquals(300, $image->size()->width()); + $this->assertEquals(200, $image->size()->height()); + } + + public function testCount(): void + { + $image = $this->testImage(); + $this->assertEquals(12, $image->count()); + } + + public function testGetIterator(): void + { + $image = $this->testImage(); + $this->assertInstanceOf(CoreInterface::class, $image->getIterator()); + } + + public function testIsAnimated(): void + { + $image = $this->testImage(); + $this->assertTrue($image->isAnimated()); + } + + public function testLoops(): void + { + $image = $this->testImage(); + $this->assertEquals(12, $image->loops()); + } + + public function testColorspace(): void + { + $image = $this->testImage(); + $this->assertInstanceOf(Colorspace::class, $image->colorspace()); + } + + public function testExif(): void + { + $image = $this->testImage(); + $this->assertInstanceOf(CollectionInterface::class, $image->exif()); + } + + public function testModify(): void + { + $image = $this->testImage(); + $result = $image->modify($this->modifier_mock); + $this->assertInstanceOf(ImageInterface::class, $result); + } + + public function testEncode(): void + { + $image = $this->testImage(); + $result = $image->encode($this->encoder_mock); + $this->assertInstanceOf(EncodedImageInterface::class, $result); + } +} diff --git a/tests/ModifierStackTest.php b/tests/ModifierStackTest.php index 65274e69..037d8803 100644 --- a/tests/ModifierStackTest.php +++ b/tests/ModifierStackTest.php @@ -2,7 +2,7 @@ namespace Intervention\Image\Tests; -use Intervention\Image\Drivers\Gd\Modifiers\GreyscaleModifier; +use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\ModifierStack; diff --git a/tests/Traits/CanCreateGdTestImage.php b/tests/Traits/CanCreateGdTestImage.php index 56921887..96f0ef79 100644 --- a/tests/Traits/CanCreateGdTestImage.php +++ b/tests/Traits/CanCreateGdTestImage.php @@ -2,16 +2,17 @@ namespace Intervention\Image\Tests\Traits; -use Intervention\Image\Collection; +use Intervention\Image\Drivers\Gd\Core; use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder; +use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Frame; -use Intervention\Image\Drivers\Gd\Image; +use Intervention\Image\Image; trait CanCreateGdTestImage { public function createTestImage($filename = 'test.jpg'): Image { - return $this->createWithImageDecoder()->handle( + return (new FilePathImageDecoder())->handle( $this->getTestImagePath($filename) ); } @@ -24,15 +25,14 @@ trait CanCreateGdTestImage imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0)); $gd3 = imagecreatetruecolor(3, 2); imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255)); - return new Image(new Collection([ - new Frame($gd1), - new Frame($gd2), - new Frame($gd3), - ])); - } - protected function createWithImageDecoder(): FilePathImageDecoder - { - return new FilePathImageDecoder(); + return new Image( + new Driver(), + new Core([ + new Frame($gd1), + new Frame($gd2), + new Frame($gd3), + ]) + ); } } diff --git a/tests/Traits/CanCreateImagickTestImage.php b/tests/Traits/CanCreateImagickTestImage.php index efc63016..8ad49366 100644 --- a/tests/Traits/CanCreateImagickTestImage.php +++ b/tests/Traits/CanCreateImagickTestImage.php @@ -3,19 +3,14 @@ namespace Intervention\Image\Tests\Traits; use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder; -use Intervention\Image\Drivers\Imagick\Image; +use Intervention\Image\Image; trait CanCreateImagickTestImage { public function createTestImage($filename = 'test.jpg'): Image { - return $this->createWithImageDecoder()->handle( + return (new FilePathImageDecoder())->handle( sprintf('%s/../images/%s', __DIR__, $filename) ); } - - protected function createWithImageDecoder(): FilePathImageDecoder - { - return new FilePathImageDecoder(); - } } diff --git a/tests/Typography/LineTest.php b/tests/Typography/LineTest.php index 480ca3ed..8616412e 100644 --- a/tests/Typography/LineTest.php +++ b/tests/Typography/LineTest.php @@ -23,11 +23,11 @@ class LineTest extends TestCase public function testSetGetPosition(): void { $line = new Line('foo'); - $this->assertEquals(0, $line->getPosition()->x()); - $this->assertEquals(0, $line->getPosition()->y()); + $this->assertEquals(0, $line->position()->x()); + $this->assertEquals(0, $line->position()->y()); $line->setPosition(new Point(10, 11)); - $this->assertEquals(10, $line->getPosition()->x()); - $this->assertEquals(11, $line->getPosition()->y()); + $this->assertEquals(10, $line->position()->x()); + $this->assertEquals(11, $line->position()->y()); } } diff --git a/tests/Typography/TextBlockTest.php b/tests/Typography/TextBlockTest.php index 8342b160..d11c9e4e 100644 --- a/tests/Typography/TextBlockTest.php +++ b/tests/Typography/TextBlockTest.php @@ -36,9 +36,9 @@ class TextBlockTest extends TestCase public function testGetLine(): void { $block = $this->getTestBlock(); - $this->assertEquals('foo', $block->getLine(0)); - $this->assertEquals('FooBar', $block->getLine(1)); - $this->assertEquals('bar', $block->getLine(2)); + $this->assertEquals('foo', $block->line(0)); + $this->assertEquals('FooBar', $block->line(1)); + $this->assertEquals('bar', $block->line(2)); } public function testLongestLine(): void @@ -65,12 +65,12 @@ class TextBlockTest extends TestCase ); $font->shouldReceive('leadingInPixels')->andReturn(30); - $font->shouldReceive('getAlign')->andReturn('left'); - $font->shouldReceive('getValign')->andReturn('bottom'); - $font->shouldReceive('getAngle')->andReturn(0); + $font->shouldReceive('alignment')->andReturn('left'); + $font->shouldReceive('valignment')->andReturn('bottom'); + $font->shouldReceive('angle')->andReturn(0); $font->shouldReceive('capHeight')->andReturn(22); - $box = $block->getBoundingBox($font, new Point(10, 15)); + $box = $block->boundingBox($font, new Point(10, 15)); $this->assertEquals(300, $box->width()); $this->assertEquals(82, $box->height()); $this->assertEquals(10, $box->pivot()->x());