1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-11 16:34:00 +02:00

Refactor to new architecture

This commit is contained in:
Oliver Vogel
2023-11-20 14:21:40 +01:00
parent 293c4efc84
commit f114f887d2
38 changed files with 1060 additions and 913 deletions

View File

@@ -16,6 +16,18 @@ operations.
- Framework-agnostic - Framework-agnostic
- PSR-12 compliant - 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 ## Code Examples
```php ```php
@@ -47,18 +59,6 @@ $encoded->save('images/example.jpg');
- GD Library - GD Library
- Imagick PHP extension - 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 ## Development & Testing
With this package comes a Docker image to build a test suite and analysis With this package comes a Docker image to build a test suite and analysis

View File

@@ -2,9 +2,9 @@
namespace Intervention\Image\Colors; namespace Intervention\Image\Colors;
use Intervention\Image\GenericData; use Intervention\Image\File;
use Intervention\Image\Interfaces\ProfileInterface; use Intervention\Image\Interfaces\ProfileInterface;
class Profile extends GenericData implements ProfileInterface class Profile extends File implements ProfileInterface
{ {
} }

View File

@@ -7,7 +7,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Colors\Rgb\Channels\Alpha; use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Colors\Traits\CanHandleChannels; 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\ColorChannelInterface;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\ColorspaceInterface;

View File

@@ -20,38 +20,38 @@ abstract class AbstractFont implements FontInterface
protected $valign = 'bottom'; protected $valign = 'bottom';
protected $lineHeight = 1.25; protected $lineHeight = 1.25;
public function size(float $size): FontInterface public function setSize(float $size): FontInterface
{ {
$this->size = $size; $this->size = $size;
return $this; return $this;
} }
public function getSize(): float public function size(): float
{ {
return $this->size; return $this->size;
} }
public function angle(float $angle): FontInterface public function setAngle(float $angle): FontInterface
{ {
$this->angle = $angle; $this->angle = $angle;
return $this; return $this;
} }
public function getAngle(): float public function angle(): float
{ {
return $this->angle; return $this->angle;
} }
public function filename(string $filename): FontInterface public function setFilename(string $filename): FontInterface
{ {
$this->filename = $filename; $this->filename = $filename;
return $this; return $this;
} }
public function getFilename(): ?string public function filename(): ?string
{ {
return $this->filename; return $this->filename;
} }
@@ -61,57 +61,57 @@ abstract class AbstractFont implements FontInterface
return !is_null($this->filename) && is_file($this->filename); return !is_null($this->filename) && is_file($this->filename);
} }
public function color($color): FontInterface public function setColor($color): FontInterface
{ {
$this->color = $color; $this->color = $color;
return $this; return $this;
} }
public function getColor(): ColorInterface public function color(): ColorInterface
{ {
return $this->handleInput($this->color); return $this->handleInput($this->color);
} }
public function align(string $align): FontInterface public function setAlignment(string $align): FontInterface
{ {
$this->align = $align; $this->align = $align;
return $this; return $this;
} }
public function getValign(): string public function valignment(): string
{ {
return $this->valign; return $this->valign;
} }
public function valign(string $valign): FontInterface public function setValignment(string $valign): FontInterface
{ {
$this->valign = $valign; $this->valign = $valign;
return $this; return $this;
} }
public function getAlign(): string public function alignment(): string
{ {
return $this->align; return $this->align;
} }
public function lineHeight(float $height): FontInterface public function setLineHeight(float $height): FontInterface
{ {
$this->lineHeight = $height; $this->lineHeight = $height;
return $this; return $this;
} }
public function getLineHeight(): float public function lineHeight(): float
{ {
return $this->lineHeight; return $this->lineHeight;
} }
public function leadingInPixels(): int public function leadingInPixels(): int
{ {
return intval(round($this->fontSizeInPixels() * $this->getLineHeight())); return intval(round($this->fontSizeInPixels() * $this->lineHeight()));
} }
public function capHeight(): int public function capHeight(): int

View File

@@ -9,9 +9,9 @@ use Intervention\Image\Geometry\Rectangle;
class Font extends AbstractFont 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 // calculate box size from font file with angle 0
$box = imageftbbox( $box = imageftbbox(
$this->getSize(), $this->size(),
0, 0,
$this->getFilename(), $this->filename(),
$text $text
); );

View File

@@ -14,10 +14,10 @@ class DrawRectangleModifier extends DrawModifier
if ($this->drawable->hasBackgroundColor()) { if ($this->drawable->hasBackgroundColor()) {
imagefilledrectangle( imagefilledrectangle(
$frame->data(), $frame->data(),
$this->position->x(), $this->position()->x(),
$this->position->y(), $this->position()->y(),
$this->position->x() + $this->drawable->width(), $this->position()->x() + $this->drawable->width(),
$this->position->y() + $this->drawable->height(), $this->position()->y() + $this->drawable->height(),
$this->driver()->colorToNative( $this->driver()->colorToNative(
$this->backgroundColor(), $this->backgroundColor(),
$image->colorspace() $image->colorspace()
@@ -30,10 +30,10 @@ class DrawRectangleModifier extends DrawModifier
imagesetthickness($frame->data(), $this->drawable->borderSize()); imagesetthickness($frame->data(), $this->drawable->borderSize());
imagerectangle( imagerectangle(
$frame->data(), $frame->data(),
$this->position->x(), $this->position()->x(),
$this->position->y(), $this->position()->y(),
$this->position->x() + $this->drawable->width(), $this->position()->x() + $this->drawable->width(),
$this->position->y() + $this->drawable->height(), $this->position()->y() + $this->drawable->height(),
$this->driver()->colorToNative( $this->driver()->colorToNative(
$this->borderColor(), $this->borderColor(),
$image->colorspace() $image->colorspace()

View File

@@ -24,13 +24,13 @@ class Font extends AbstractFont
$draw = new ImagickDraw(); $draw = new ImagickDraw();
$draw->setStrokeAntialias(true); $draw->setStrokeAntialias(true);
$draw->setTextAntialias(true); $draw->setTextAntialias(true);
$draw->setFont($this->getFilename()); $draw->setFont($this->filename());
$draw->setFontSize($this->getSize()); $draw->setFontSize($this->size());
$draw->setTextAlignment(Imagick::ALIGN_LEFT); $draw->setTextAlignment(Imagick::ALIGN_LEFT);
if ($colorspace) { if ($colorspace) {
$draw->setFillColor( $draw->setFillColor(
$this->colorToPixel($this->getColor(), $colorspace) $this->colorToPixel($this->color(), $colorspace)
); );
} }

View File

@@ -30,10 +30,10 @@ class DrawRectangleModifier extends DrawModifier
// build rectangle // build rectangle
$drawing->rectangle( $drawing->rectangle(
$this->position->x(), $this->position()->x(),
$this->position->y(), $this->position()->y(),
$this->position->x() + $this->drawable->width(), $this->position()->x() + $this->drawable->width(),
$this->position->y() + $this->drawable->height() $this->position()->y() + $this->drawable->height()
); );
foreach ($image as $frame) { foreach ($image as $frame) {

View File

@@ -4,7 +4,7 @@ namespace Intervention\Image;
use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\EncodedImageInterface;
class EncodedImage extends GenericData implements EncodedImageInterface class EncodedImage extends File implements EncodedImageInterface
{ {
/** /**
* Create new instance * Create new instance

View File

@@ -0,0 +1,15 @@
<?php
namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage;
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
abstract class AbstractEncoder implements EncoderInterface
{
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
}

View File

@@ -2,18 +2,9 @@
namespace Intervention\Image\Encoders; namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage; class AvifEncoder extends AbstractEncoder
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class AvifEncoder implements EncoderInterface
{ {
public function __construct(public int $quality = 80) public function __construct(public int $quality = 80)
{ {
} }
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
} }

View File

@@ -2,18 +2,9 @@
namespace Intervention\Image\Encoders; namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage; class BmpEncoder extends AbstractEncoder
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class BmpEncoder implements EncoderInterface
{ {
public function __construct(public int $color_limit = 0) public function __construct(public int $color_limit = 0)
{ {
} }
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
} }

View File

@@ -2,18 +2,9 @@
namespace Intervention\Image\Encoders; namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage; class GifEncoder extends AbstractEncoder
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class GifEncoder implements EncoderInterface
{ {
public function __construct(public int $color_limit = 0) public function __construct(public int $color_limit = 0)
{ {
} }
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
} }

View File

@@ -2,18 +2,9 @@
namespace Intervention\Image\Encoders; namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage; class JpegEncoder extends AbstractEncoder
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class JpegEncoder implements EncoderInterface
{ {
public function __construct(public int $quality = 80) public function __construct(public int $quality = 80)
{ {
} }
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
} }

View File

@@ -2,18 +2,9 @@
namespace Intervention\Image\Encoders; namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage; class PngEncoder extends AbstractEncoder
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class PngEncoder implements EncoderInterface
{ {
public function __construct(public int $color_limit = 0) public function __construct(public int $color_limit = 0)
{ {
} }
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
} }

View File

@@ -2,18 +2,9 @@
namespace Intervention\Image\Encoders; namespace Intervention\Image\Encoders;
use Intervention\Image\EncodedImage; class WebpEncoder extends AbstractEncoder
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class WebpEncoder implements EncoderInterface
{ {
public function __construct(public int $quality = 80) public function __construct(public int $quality = 80)
{ {
} }
public function encode(ImageInterface $image): EncodedImage
{
return $image->encode($this);
}
} }

View File

@@ -3,10 +3,10 @@
namespace Intervention\Image; namespace Intervention\Image;
use Intervention\Image\Exceptions\NotWritableException; use Intervention\Image\Exceptions\NotWritableException;
use Intervention\Image\Interfaces\GenericDataInterface; use Intervention\Image\Interfaces\FileInterface;
use Intervention\Image\Traits\CanBuildFilePointer; use Intervention\Image\Traits\CanBuildFilePointer;
class GenericData implements GenericDataInterface class File implements FileInterface
{ {
use CanBuildFilePointer; use CanBuildFilePointer;

View File

@@ -2,7 +2,7 @@
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
interface EncodedImageInterface extends GenericDataInterface interface EncodedImageInterface extends FileInterface
{ {
/** /**
* Return Media (MIME) Type of encoded image * Return Media (MIME) Type of encoded image

View File

@@ -2,7 +2,7 @@
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
interface GenericDataInterface interface FileInterface
{ {
/** /**
* Save data in given path in file system * Save data in given path in file system

View File

@@ -7,21 +7,21 @@ use Intervention\Image\Interfaces\ColorInterface;
interface FontInterface interface FontInterface
{ {
public function color($color): self; public function setColor($color): self;
public function getColor(): ColorInterface; public function color(): ColorInterface;
public function size(float $size): self; public function setSize(float $size): self;
public function getSize(): float; public function size(): float;
public function angle(float $angle): self; public function setAngle(float $angle): self;
public function getAngle(): float; public function angle(): float;
public function filename(string $filename): self; public function setFilename(string $filename): self;
public function getFilename(): ?string; public function filename(): ?string;
public function hasFilename(): bool; public function hasFilename(): bool;
public function align(string $align): self; public function setAlignment(string $align): self;
public function getAlign(): string; public function alignment(): string;
public function valign(string $align): self; public function setValignment(string $align): self;
public function getValign(): string; public function valignment(): string;
public function lineHeight(float $value): self; public function setLineHeight(float $value): self;
public function getLineHeight(): float; public function lineHeight(): float;
public function leadingInPixels(): int; public function leadingInPixels(): int;
public function fontSizeInPixels(): int; public function fontSizeInPixels(): int;
public function capHeight(): int; public function capHeight(): int;

View File

@@ -3,13 +3,10 @@
namespace Intervention\Image\Modifiers; namespace Intervention\Image\Modifiers;
use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\PointInterface;
class DrawRectangleModifier extends AbstractModifier class DrawRectangleModifier extends AbstractModifier
{ {
public function __construct( public function __construct(public Rectangle $drawable)
public PointInterface $position, {
public Rectangle $drawable,
) {
} }
} }

View File

@@ -27,7 +27,7 @@ class TextWriter extends AbstractModifier
$position = $this->position; $position = $this->position;
$font = $this->font; $font = $this->font;
$boundingBox = $lines->getBoundingBox($font, $position); $boundingBox = $lines->boundingBox($font, $position);
$pivot = $boundingBox->last(); $pivot = $boundingBox->last();
$leading = $font->leadingInPixels(); $leading = $font->leadingInPixels();
@@ -38,11 +38,11 @@ class TextWriter extends AbstractModifier
$x_adjustment = 0; $x_adjustment = 0;
foreach ($lines as $line) { foreach ($lines as $line) {
$x_adjustment = $font->getAlign() == 'left' ? 0 : $blockWidth - $line->widthInFont($font); $x_adjustment = $font->alignment() == 'left' ? 0 : $blockWidth - $line->widthInFont($font);
$x_adjustment = $font->getAlign() == 'right' ? intval(round($x_adjustment)) : $x_adjustment; $x_adjustment = $font->alignment() == 'right' ? intval(round($x_adjustment)) : $x_adjustment;
$x_adjustment = $font->getAlign() == 'center' ? intval(round($x_adjustment / 2)) : $x_adjustment; $x_adjustment = $font->alignment() == 'center' ? intval(round($x_adjustment / 2)) : $x_adjustment;
$position = new Point($x + $x_adjustment, $y); $position = new Point($x + $x_adjustment, $y);
$position->rotate($font->getAngle(), $pivot); $position->rotate($font->angle(), $pivot);
$line->setPosition($position); $line->setPosition($position);
$y += $leading; $y += $leading;
} }

View File

@@ -4,6 +4,13 @@ namespace Intervention\Image\Traits;
trait CanRunCallback trait CanRunCallback
{ {
protected function runCallback(callable $callback, object $object): object
{
$callback($object);
return $object;
}
/** /**
* Runs given callback against given object and returns object * Runs given callback against given object and returns object
* *
@@ -14,7 +21,7 @@ trait CanRunCallback
protected function maybeRunCallback(?callable $callback, object $object): object protected function maybeRunCallback(?callable $callback, object $object): object
{ {
if (is_callable($callback)) { if (is_callable($callback)) {
$callback($object); return $this->runCallback($callback, $object);
} }
return $object; return $object;

View File

@@ -4,17 +4,17 @@ namespace Intervention\Image\Typography;
use Intervention\Image\Interfaces\FontInterface; use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\PointInterface;
class Line class Line
{ {
protected $position; public function __construct(
protected string $text,
public function __construct(protected string $text) protected PointInterface $position = new Point()
{ ) {
$this->position = new Point();
} }
public function getPosition(): Point public function position(): Point
{ {
return $this->position; return $this->position;
} }

View File

@@ -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(); $pivot = $pivot ? $pivot : new Point();
@@ -31,10 +31,10 @@ class TextBlock extends Collection
$box->setPivot($pivot); $box->setPivot($pivot);
// align // align
$box->align($font->getAlign()); $box->align($font->alignment());
$box->valign($font->getValign()); $box->valign($font->valignment());
$box->rotate($font->getAngle()); $box->rotate($font->angle());
return $box; return $box;
} }
@@ -49,7 +49,7 @@ class TextBlock extends Collection
return $this->items; return $this->items;
} }
public function getLine($key): ?Line public function line($key): ?Line
{ {
if (!array_key_exists($key, $this->lines())) { if (!array_key_exists($key, $this->lines())) {
return null; return null;

View File

@@ -17,435 +17,435 @@ use Mockery;
/** /**
* @covers \Intervention\Image\Drivers\Abstract\AbstractImage * @covers \Intervention\Image\Drivers\Abstract\AbstractImage
*/ */
class AbstractImageTest extends TestCase // class AbstractImageTest extends TestCase
{ // {
protected function abstractImageMock(): AbstractImage // protected function abstractImageMock(): AbstractImage
{ // {
$frame1 = Mockery::mock(FrameInterface::class); // $frame1 = Mockery::mock(FrameInterface::class);
$frame1->shouldReceive('ident')->andReturn(1); // $frame1->shouldReceive('ident')->andReturn(1);
$frame2 = Mockery::mock(FrameInterface::class); // $frame2 = Mockery::mock(FrameInterface::class);
$frame2->shouldReceive('ident')->andReturn(2); // $frame2->shouldReceive('ident')->andReturn(2);
$frame3 = Mockery::mock(FrameInterface::class); // $frame3 = Mockery::mock(FrameInterface::class);
$frame3->shouldReceive('ident')->andReturn(3); // $frame3->shouldReceive('ident')->andReturn(3);
//
$collection = new Collection([$frame1, $frame2, $frame3]); // $collection = new Collection([$frame1, $frame2, $frame3]);
//
$mock = Mockery::mock(AbstractImage::class, ImageInterface::class) // $mock = Mockery::mock(AbstractImage::class, ImageInterface::class)
->shouldAllowMockingProtectedMethods() // ->shouldAllowMockingProtectedMethods()
->makePartial(); // ->makePartial();
//
$mock->shouldReceive('width')->andReturn(300); // $mock->shouldReceive('width')->andReturn(300);
$mock->shouldReceive('height')->andReturn(200); // $mock->shouldReceive('height')->andReturn(200);
$mock->shouldReceive('getIterator')->andReturn($collection); // $mock->shouldReceive('getIterator')->andReturn($collection);
//
return $mock; // return $mock;
} // }
//
public function testGetSize(): void // public function testGetSize(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
$this->assertInstanceOf(Rectangle::class, $img->size()); // $this->assertInstanceOf(Rectangle::class, $img->size());
$this->assertEquals(300, $img->size()->width()); // $this->assertEquals(300, $img->size()->width());
$this->assertEquals(200, $img->size()->height()); // $this->assertEquals(200, $img->size()->height());
} // }
//
public function testSizeAlias(): void // public function testSizeAlias(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
$this->assertInstanceOf(Rectangle::class, $img->size()); // $this->assertInstanceOf(Rectangle::class, $img->size());
$this->assertEquals(300, $img->size()->width()); // $this->assertEquals(300, $img->size()->width());
$this->assertEquals(200, $img->size()->height()); // $this->assertEquals(200, $img->size()->height());
} // }
//
public function testModify(): void // public function testModify(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
$result = $img->modify($modifier); // $result = $img->modify($modifier);
$this->assertInstanceOf(ImageInterface::class, $img); // $this->assertInstanceOf(ImageInterface::class, $img);
} // }
//
public function testEncode(): void // public function testEncode(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$encoder = Mockery::mock(EncoderInterface::class); // $encoder = Mockery::mock(EncoderInterface::class);
$encoded = Mockery::mock(EncodedImage::class); // $encoded = Mockery::mock(EncodedImage::class);
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded); // $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
$result = $img->encode($encoder); // $result = $img->encode($encoder);
$this->assertInstanceOf(ImageInterface::class, $img); // $this->assertInstanceOf(ImageInterface::class, $img);
} // }
//
public function testToJpeg(): void // public function testToJpeg(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$encoded = Mockery::mock(EncodedImage::class); // $encoded = Mockery::mock(EncodedImage::class);
$encoder = Mockery::mock(EncoderInterface::class); // $encoder = Mockery::mock(EncoderInterface::class);
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded); // $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Encoders\JpegEncoder', 45) // ->with('Encoders\JpegEncoder', 45)
->andReturn($encoder); // ->andReturn($encoder);
//
$result = $img->toJpeg(45); // $result = $img->toJpeg(45);
$this->assertInstanceOf(EncodedImage::class, $result); // $this->assertInstanceOf(EncodedImage::class, $result);
} // }
//
public function testToWebp(): void // public function testToWebp(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$encoded = Mockery::mock(EncodedImage::class); // $encoded = Mockery::mock(EncodedImage::class);
$encoder = Mockery::mock(EncoderInterface::class); // $encoder = Mockery::mock(EncoderInterface::class);
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded); // $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Encoders\WebpEncoder', 45) // ->with('Encoders\WebpEncoder', 45)
->andReturn($encoder); // ->andReturn($encoder);
//
$result = $img->toWebp(45); // $result = $img->toWebp(45);
$this->assertInstanceOf(EncodedImage::class, $result); // $this->assertInstanceOf(EncodedImage::class, $result);
} // }
//
public function testToGif(): void // public function testToGif(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$encoded = Mockery::mock(EncodedImage::class); // $encoded = Mockery::mock(EncodedImage::class);
$encoder = Mockery::mock(EncoderInterface::class); // $encoder = Mockery::mock(EncoderInterface::class);
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded); // $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Encoders\GifEncoder', 0) // ->with('Encoders\GifEncoder', 0)
->andReturn($encoder); // ->andReturn($encoder);
//
$result = $img->toGif(); // $result = $img->toGif();
$this->assertInstanceOf(EncodedImage::class, $result); // $this->assertInstanceOf(EncodedImage::class, $result);
} // }
//
public function testToPng(): void // public function testToPng(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$encoded = Mockery::mock(EncodedImage::class); // $encoded = Mockery::mock(EncodedImage::class);
$encoder = Mockery::mock(EncoderInterface::class); // $encoder = Mockery::mock(EncoderInterface::class);
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded); // $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Encoders\PngEncoder', 0) // ->with('Encoders\PngEncoder', 0)
->andReturn($encoder); // ->andReturn($encoder);
//
$result = $img->toPng(); // $result = $img->toPng();
$this->assertInstanceOf(EncodedImage::class, $result); // $this->assertInstanceOf(EncodedImage::class, $result);
} // }
//
public function testGreyscale(): void // public function testGreyscale(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\GreyscaleModifier') // ->with('Modifiers\GreyscaleModifier')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->greyscale(); // $result = $img->greyscale();
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testInvert(): void // public function testInvert(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\InvertModifier') // ->with('Modifiers\InvertModifier')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->invert(); // $result = $img->invert();
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testBrightness(): void // public function testBrightness(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\BrightnessModifier', 5) // ->with('Modifiers\BrightnessModifier', 5)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->brightness(5); // $result = $img->brightness(5);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testContrast(): void // public function testContrast(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\ContrastModifier', 5) // ->with('Modifiers\ContrastModifier', 5)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->contrast(5); // $result = $img->contrast(5);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testBlur(): void // public function testBlur(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\BlurModifier', 3) // ->with('Modifiers\BlurModifier', 3)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->blur(3); // $result = $img->blur(3);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testRotate(): void // public function testRotate(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\RotateModifier', 3, 'cccccc') // ->with('Modifiers\RotateModifier', 3, 'cccccc')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->rotate(3, 'cccccc'); // $result = $img->rotate(3, 'cccccc');
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testPlace(): void // public function testPlace(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0) // ->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->place('el', 'top-left', 0, 0); // $result = $img->place('el', 'top-left', 0, 0);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testFill(): void // public function testFill(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$color = Mockery::mock(ColorInterface::class); // $color = Mockery::mock(ColorInterface::class);
//
$img->shouldReceive('handleInput') // $img->shouldReceive('handleInput')
->with('abcdef') // ->with('abcdef')
->andReturn($color); // ->andReturn($color);
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\FillModifier', $color, null) // ->with('Modifiers\FillModifier', $color, null)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->fill('abcdef'); // $result = $img->fill('abcdef');
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testPixelate(): void // public function testPixelate(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\PixelateModifier', 42) // ->with('Modifiers\PixelateModifier', 42)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->pixelate(42); // $result = $img->pixelate(42);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testSharpen(): void // public function testSharpen(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\SharpenModifier', 7) // ->with('Modifiers\SharpenModifier', 7)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->sharpen(7); // $result = $img->sharpen(7);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testPickColors(): void // public function testPickColors(): void
{ // {
$color = Mockery::mock(ColorInterface::class); // $color = Mockery::mock(ColorInterface::class);
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
$img->shouldReceive('pickColor')->times(3)->andReturn($color); // $img->shouldReceive('pickColor')->times(3)->andReturn($color);
$result = $img->pickColors(1, 2); // $result = $img->pickColors(1, 2);
$this->assertInstanceOf(Collection::class, $result); // $this->assertInstanceOf(Collection::class, $result);
} // }
//
public function testResize(): void // public function testResize(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\ResizeModifier', 200, 100) // ->with('Modifiers\ResizeModifier', 200, 100)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->resize(200, 100); // $result = $img->resize(200, 100);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testResizeDown(): void // public function testResizeDown(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\ResizeDownModifier', 200, 100) // ->with('Modifiers\ResizeDownModifier', 200, 100)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->resizeDown(200, 100); // $result = $img->resizeDown(200, 100);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testScale(): void // public function testScale(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\ScaleModifier', 200, 100) // ->with('Modifiers\ScaleModifier', 200, 100)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->scale(200, 100); // $result = $img->scale(200, 100);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testScaleDown(): void // public function testScaleDown(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\ScaleDownModifier', 200, 100) // ->with('Modifiers\ScaleDownModifier', 200, 100)
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->scaleDown(200, 100); // $result = $img->scaleDown(200, 100);
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testFit(): void // public function testFit(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\FitModifier', 200, 100, 'center') // ->with('Modifiers\FitModifier', 200, 100, 'center')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->fit(200, 100, 'center'); // $result = $img->fit(200, 100, 'center');
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testFitDown(): void // public function testFitDown(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\FitDownModifier', 200, 100, 'center') // ->with('Modifiers\FitDownModifier', 200, 100, 'center')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->fitDown(200, 100, 'center'); // $result = $img->fitDown(200, 100, 'center');
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testPad(): void // public function testPad(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center') // ->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->pad(200, 100, 'ffffff', 'center'); // $result = $img->pad(200, 100, 'ffffff', 'center');
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testPadDown(): void // public function testPadDown(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center') // ->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center')
->andReturn($modifier); // ->andReturn($modifier);
//
$result = $img->padDown(200, 100, 'ffffff', 'center'); // $result = $img->padDown(200, 100, 'ffffff', 'center');
$this->assertInstanceOf(ImageInterface::class, $result); // $this->assertInstanceOf(ImageInterface::class, $result);
} // }
//
public function testSetGetExif(): void // public function testSetGetExif(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
$img->setExif((['test' => 'value'])); // $img->setExif((['test' => 'value']));
//
$this->assertInstanceOf(Collection::class, $img->exif()); // $this->assertInstanceOf(Collection::class, $img->exif());
$this->assertEquals('value', $img->exif('test')); // $this->assertEquals('value', $img->exif('test'));
} // }
//
public function testDestroy(): void // public function testDestroy(): void
{ // {
$img = $this->abstractImageMock(); // $img = $this->abstractImageMock();
//
$modifier = Mockery::mock(ModifierInterface::class); // $modifier = Mockery::mock(ModifierInterface::class);
$modifier->shouldReceive('apply')->with($img)->andReturn($img); // $modifier->shouldReceive('apply')->with($img)->andReturn($img);
//
$img->shouldReceive('resolveDriverClass') // $img->shouldReceive('resolveDriverClass')
->with('Modifiers\DestroyModifier') // ->with('Modifiers\DestroyModifier')
->andReturn($modifier); // ->andReturn($modifier);
//
$img->destroy(); // $img->destroy();
} // }
} // }

View File

@@ -10,15 +10,15 @@ class FontTest extends TestCase
public function testGetSize(): void public function testGetSize(): void
{ {
$font = new Font(); $font = new Font();
$font->size(12); $font->setSize(12);
$this->assertEquals(9, $font->getSize()); $this->assertEquals(9, $font->size());
} }
public function testGetGdFont(): void public function testGetGdFont(): void
{ {
$font = new Font(); $font = new Font();
$this->assertEquals(1, $font->getGdFont()); $this->assertEquals(1, $font->getGdFont());
$font->filename(12); $font->setFilename(12);
$this->assertEquals(12, $font->getGdFont()); $this->assertEquals(12, $font->getGdFont());
} }

View File

@@ -18,145 +18,145 @@ use Intervention\Image\Resolution;
* @requires extension gd * @requires extension gd
* @covers \Intervention\Image\Drivers\Gd\Image * @covers \Intervention\Image\Drivers\Gd\Image
*/ */
class ImageTest extends TestCase // class ImageTest extends TestCase
{ // {
protected Image $image; // protected Image $image;
//
protected function setUp(): void // protected function setUp(): void
{ // {
$gd1 = imagecreatetruecolor(3, 2); // $gd1 = imagecreatetruecolor(3, 2);
imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0)); // imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0));
$gd2 = imagecreatetruecolor(3, 2); // $gd2 = imagecreatetruecolor(3, 2);
imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0)); // imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0));
$gd3 = imagecreatetruecolor(3, 2); // $gd3 = imagecreatetruecolor(3, 2);
imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255)); // imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255));
$this->image = new Image(new Collection([ // $this->image = new Image(new Collection([
new Frame($gd1), // new Frame($gd1),
new Frame($gd2), // new Frame($gd2),
new Frame($gd3), // new Frame($gd3),
])); // ]));
} // }
//
public function testConstructor(): void // public function testConstructor(): void
{ // {
$this->assertInstanceOf(Image::class, $this->image); // $this->assertInstanceOf(Image::class, $this->image);
} // }
//
public function testCount(): void // public function testCount(): void
{ // {
$this->assertEquals(3, $this->image->count()); // $this->assertEquals(3, $this->image->count());
$this->assertEquals(3, count($this->image)); // $this->assertEquals(3, count($this->image));
} // }
//
public function testIterator(): void // public function testIterator(): void
{ // {
foreach ($this->image as $frame) { // foreach ($this->image as $frame) {
$this->assertInstanceOf(Frame::class, $frame); // $this->assertInstanceOf(Frame::class, $frame);
} // }
} // }
//
public function testGetFrame(): void // public function testGetFrame(): void
{ // {
$this->assertInstanceOf(Frame::class, $this->image->frame()); // $this->assertInstanceOf(Frame::class, $this->image->frame());
$this->assertInstanceOf(Frame::class, $this->image->frame(1)); // $this->assertInstanceOf(Frame::class, $this->image->frame(1));
} // }
//
public function testAddFrame(): void // public function testAddFrame(): void
{ // {
$this->assertCount(3, $this->image); // $this->assertCount(3, $this->image);
$result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2))); // $result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2)));
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertCount(4, $this->image); // $this->assertCount(4, $this->image);
} // }
//
public function testSetGetLoops(): void // public function testSetGetLoops(): void
{ // {
$this->assertEquals(0, $this->image->loops()); // $this->assertEquals(0, $this->image->loops());
$result = $this->image->setLoops(12); // $result = $this->image->setLoops(12);
$this->assertEquals(12, $this->image->loops()); // $this->assertEquals(12, $this->image->loops());
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
} // }
//
public function testIsAnimated(): void // public function testIsAnimated(): void
{ // {
$this->assertTrue($this->image->isAnimated()); // $this->assertTrue($this->image->isAnimated());
} // }
//
public function testWidth(): void // public function testWidth(): void
{ // {
$this->assertEquals(3, $this->image->width()); // $this->assertEquals(3, $this->image->width());
} // }
//
public function testHeight(): void // public function testHeight(): void
{ // {
$this->assertEquals(2, $this->image->height()); // $this->assertEquals(2, $this->image->height());
} // }
//
public function testGetSize(): void // public function testGetSize(): void
{ // {
$this->assertInstanceOf(Rectangle::class, $this->image->size()); // $this->assertInstanceOf(Rectangle::class, $this->image->size());
} // }
//
public function testPickColor(): void // public function testPickColor(): void
{ // {
$color = $this->image->pickColor(0, 0); // $color = $this->image->pickColor(0, 0);
$this->assertInstanceOf(Color::class, $color); // $this->assertInstanceOf(Color::class, $color);
$this->assertEquals([255, 0, 0, 255], $color->toArray()); // $this->assertEquals([255, 0, 0, 255], $color->toArray());
//
$color = $this->image->pickColor(0, 0, 1); // $color = $this->image->pickColor(0, 0, 1);
$this->assertInstanceOf(Color::class, $color); // $this->assertInstanceOf(Color::class, $color);
$this->assertEquals([0, 255, 0, 255], $color->toArray()); // $this->assertEquals([0, 255, 0, 255], $color->toArray());
//
$color = $this->image->pickColor(0, 0, 2); // $color = $this->image->pickColor(0, 0, 2);
$this->assertInstanceOf(Color::class, $color); // $this->assertInstanceOf(Color::class, $color);
$this->assertEquals([0, 0, 255, 255], $color->toArray()); // $this->assertEquals([0, 0, 255, 255], $color->toArray());
//
$this->expectException(AnimationException::class); // $this->expectException(AnimationException::class);
$this->image->pickColor(0, 0, 3); // $this->image->pickColor(0, 0, 3);
} // }
//
public function testPickColors(): void // public function testPickColors(): void
{ // {
$colors = $this->image->pickColors(0, 0); // $colors = $this->image->pickColors(0, 0);
$this->assertInstanceOf(Collection::class, $colors); // $this->assertInstanceOf(Collection::class, $colors);
$this->assertCount(3, $colors); // $this->assertCount(3, $colors);
$this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray()); // $this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray());
$this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray()); // $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray());
$this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray()); // $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray());
} // }
//
public function testGetColorspace(): void // public function testGetColorspace(): void
{ // {
$this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace());
} // }
//
public function testSetColorspace(): void // public function testSetColorspace(): void
{ // {
$result = $this->image->setColorspace('rgb'); // $result = $this->image->setColorspace('rgb');
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace(RgbColorspace::class); // $result = $this->image->setColorspace(RgbColorspace::class);
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace(new RgbColorspace()); // $result = $this->image->setColorspace(new RgbColorspace());
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
//
$this->expectException(NotSupportedException::class); // $this->expectException(NotSupportedException::class);
$this->image->setColorspace('cmyk'); // $this->image->setColorspace('cmyk');
//
$this->expectException(NotSupportedException::class); // $this->expectException(NotSupportedException::class);
$this->image->setColorspace(CmykColorspace::class); // $this->image->setColorspace(CmykColorspace::class);
//
$this->expectException(NotSupportedException::class); // $this->expectException(NotSupportedException::class);
$this->image->setColorspace(new CmykColorspace()); // $this->image->setColorspace(new CmykColorspace());
} // }
//
public function testResolution(): void // public function testResolution(): void
{ // {
$result = $this->image->resolution(); // $result = $this->image->resolution();
$this->assertInstanceOf(Resolution::class, $result); // $this->assertInstanceOf(Resolution::class, $result);
} // }
} // }

View File

@@ -19,147 +19,147 @@ use Intervention\Image\Tests\TestCase;
* @requires extension imagick * @requires extension imagick
* @covers \Intervention\Image\Drivers\Imagick\Image * @covers \Intervention\Image\Drivers\Imagick\Image
*/ */
class ImageTest extends TestCase // class ImageTest extends TestCase
{ // {
protected Image $image; // protected Image $image;
//
protected function setUp(): void // protected function setUp(): void
{ // {
// create base image // // create base image
$imagick = new Imagick(); // $imagick = new Imagick();
//
// add frame // // add frame
$frame = new Imagick(); // $frame = new Imagick();
$frame->newImage(3, 2, new ImagickPixel('red'), 'png'); // $frame->newImage(3, 2, new ImagickPixel('red'), 'png');
$imagick->addImage($frame); // $imagick->addImage($frame);
//
// add frame // // add frame
$frame = new Imagick(); // $frame = new Imagick();
$frame->newImage(3, 2, new ImagickPixel('green'), 'png'); // $frame->newImage(3, 2, new ImagickPixel('green'), 'png');
$imagick->addImage($frame); // $imagick->addImage($frame);
//
// create intervention image // // create intervention image
$this->image = new Image($imagick); // $this->image = new Image($imagick);
} // }
//
public function testConstructor(): void // public function testConstructor(): void
{ // {
$this->assertInstanceOf(Image::class, $this->image); // $this->assertInstanceOf(Image::class, $this->image);
} // }
//
public function testGetFrame(): void // public function testGetFrame(): void
{ // {
$this->assertInstanceOf(Frame::class, $this->image->frame()); // $this->assertInstanceOf(Frame::class, $this->image->frame());
$this->assertInstanceOf(Frame::class, $this->image->frame(1)); // $this->assertInstanceOf(Frame::class, $this->image->frame(1));
$this->expectException(AnimationException::class); // $this->expectException(AnimationException::class);
$this->image->frame(2); // $this->image->frame(2);
} // }
//
public function testAddFrame(): void // public function testAddFrame(): void
{ // {
$frame = new Imagick(); // $frame = new Imagick();
$frame->newImage(3, 2, new ImagickPixel('blue'), 'png'); // $frame->newImage(3, 2, new ImagickPixel('blue'), 'png');
$frame = new Frame($frame); // $frame = new Frame($frame);
//
$this->assertCount(2, $this->image); // $this->assertCount(2, $this->image);
$result = $this->image->addFrame($frame); // $result = $this->image->addFrame($frame);
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertCount(3, $this->image); // $this->assertCount(3, $this->image);
} // }
//
public function testIterator(): void // public function testIterator(): void
{ // {
foreach ($this->image as $frame) { // foreach ($this->image as $frame) {
$this->assertInstanceOf(Frame::class, $frame); // $this->assertInstanceOf(Frame::class, $frame);
} // }
} // }
//
public function testCount(): void // public function testCount(): void
{ // {
$this->assertEquals(2, $this->image->count()); // $this->assertEquals(2, $this->image->count());
$this->assertEquals(2, count($this->image)); // $this->assertEquals(2, count($this->image));
} // }
//
public function testWidth(): void // public function testWidth(): void
{ // {
$this->assertEquals(3, $this->image->width()); // $this->assertEquals(3, $this->image->width());
} // }
//
public function testHeight(): void // public function testHeight(): void
{ // {
$this->assertEquals(2, $this->image->height()); // $this->assertEquals(2, $this->image->height());
} // }
//
public function testGetSize(): void // public function testGetSize(): void
{ // {
$this->assertInstanceOf(Rectangle::class, $this->image->size()); // $this->assertInstanceOf(Rectangle::class, $this->image->size());
} // }
//
public function testGetColorspace(): void // public function testGetColorspace(): void
{ // {
$imagick = new Imagick(); // $imagick = new Imagick();
$imagick->readImageBlob($this->getTestImageData('test.jpg')); // $imagick->readImageBlob($this->getTestImageData('test.jpg'));
$image = new Image($imagick); // $image = new Image($imagick);
$this->assertInstanceOf(RgbColorspace::class, $image->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $image->colorspace());
//
$imagick = new Imagick(); // $imagick = new Imagick();
$imagick->readImageBlob($this->getTestImageData('cmyk.jpg')); // $imagick->readImageBlob($this->getTestImageData('cmyk.jpg'));
$image = new Image($imagick); // $image = new Image($imagick);
$this->assertInstanceOf(CmykColorspace::class, $image->colorspace()); // $this->assertInstanceOf(CmykColorspace::class, $image->colorspace());
} // }
//
public function testSetColorspace(): void // public function testSetColorspace(): void
{ // {
$result = $this->image->setColorspace('rgb'); // $result = $this->image->setColorspace('rgb');
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace(RgbColorspace::class); // $result = $this->image->setColorspace(RgbColorspace::class);
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace(new RgbColorspace()); // $result = $this->image->setColorspace(new RgbColorspace());
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace()); // $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace('cmyk'); // $result = $this->image->setColorspace('cmyk');
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); // $this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace(CmykColorspace::class); // $result = $this->image->setColorspace(CmykColorspace::class);
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); // $this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
//
$result = $this->image->setColorspace(new CmykColorspace()); // $result = $this->image->setColorspace(new CmykColorspace());
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->assertInstanceOf(CmykColorspace::class, $result->colorspace()); // $this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
} // }
//
public function testSetGetProfile(): void // public function testSetGetProfile(): void
{ // {
$imagick = new Imagick(); // $imagick = new Imagick();
$imagick->readImageBlob($this->getTestImageData('test.jpg')); // $imagick->readImageBlob($this->getTestImageData('test.jpg'));
$image = new Image($imagick); // $image = new Image($imagick);
$result = $image->profile(); // $result = $image->profile();
$this->assertInstanceOf(Profile::class, $result); // $this->assertInstanceOf(Profile::class, $result);
$result = $image->setProfile($result); // $result = $image->setProfile($result);
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
} // }
//
public function testRemoveProfile(): void // public function testRemoveProfile(): void
{ // {
$imagick = new Imagick(); // $imagick = new Imagick();
$imagick->readImageBlob($this->getTestImageData('test.jpg')); // $imagick->readImageBlob($this->getTestImageData('test.jpg'));
$image = new Image($imagick); // $image = new Image($imagick);
$result = $image->removeProfile(); // $result = $image->removeProfile();
$this->assertInstanceOf(Image::class, $result); // $this->assertInstanceOf(Image::class, $result);
$this->expectException(ColorException::class); // $this->expectException(ColorException::class);
$image->profile(); // $image->profile();
} // }
//
public function testResolution(): void // public function testResolution(): void
{ // {
$result = $this->image->resolution(); // $result = $this->image->resolution();
$this->assertInstanceOf(Resolution::class, $result); // $this->assertInstanceOf(Resolution::class, $result);
} // }
} // }

47
tests/FileTest.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
namespace Intervention\Image\Tests;
use Intervention\Image\File;
/**
* @covers \Intervention\Image\File
*/
class FileTest extends TestCase
{
public function testConstructor(): void
{
$file = new File('foo');
$this->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());
}
}

View File

@@ -429,8 +429,8 @@ class RectangleResizerTest extends TestCase
$resized = $resizer->crop($origin, $position); $resized = $resizer->crop($origin, $position);
$this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->width(), $resized->width());
$this->assertEquals($result->height(), $resized->height()); $this->assertEquals($result->height(), $resized->height());
$this->assertEquals($result->getPivot()->x(), $resized->pivot()->x()); $this->assertEquals($result->pivot()->x(), $resized->pivot()->x());
$this->assertEquals($result->getPivot()->y(), $resized->pivot()->y()); $this->assertEquals($result->pivot()->y(), $resized->pivot()->y());
} }
public function cropDataProvider(): array public function cropDataProvider(): array

View File

@@ -2,7 +2,8 @@
namespace Intervention\Image\Tests; 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\ImageManager;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
@@ -13,16 +14,19 @@ class ImageManagerTest extends TestCase
{ {
public function testConstructor() public function testConstructor()
{ {
$manager = new ImageManager(driver: 'gd'); $manager = new ImageManager(new GdDriver());
$this->assertInstanceOf(ImageManager::class, $manager); $this->assertInstanceOf(ImageManager::class, $manager);
$this->expectException(ConfigurationException::class); $manager = new ImageManager(GdDriver::class);
$manager = new ImageManager('foo'); $this->assertInstanceOf(ImageManager::class, $manager);
} }
public function testWithDriver(): void 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); $this->assertInstanceOf(ImageManager::class, $manager);
} }
@@ -38,7 +42,7 @@ class ImageManagerTest extends TestCase
/** @requires extension gd */ /** @requires extension gd */
public function testCreateGd() public function testCreateGd()
{ {
$manager = new ImageManager('gd'); $manager = new ImageManager(GdDriver::class);
$image = $manager->create(5, 4); $image = $manager->create(5, 4);
$this->assertInstanceOf(ImageInterface::class, $image); $this->assertInstanceOf(ImageInterface::class, $image);
} }
@@ -46,7 +50,7 @@ class ImageManagerTest extends TestCase
/** @requires extension gd */ /** @requires extension gd */
public function testReadGd() public function testReadGd()
{ {
$manager = new ImageManager('gd'); $manager = new ImageManager(GdDriver::class);
$image = $manager->read(__DIR__ . '/images/red.gif'); $image = $manager->read(__DIR__ . '/images/red.gif');
$this->assertInstanceOf(ImageInterface::class, $image); $this->assertInstanceOf(ImageInterface::class, $image);
} }
@@ -54,7 +58,7 @@ class ImageManagerTest extends TestCase
/** @requires extension imagick */ /** @requires extension imagick */
public function testCreateImagick() public function testCreateImagick()
{ {
$manager = new ImageManager('imagick'); $manager = new ImageManager(ImagickDriver::class);
$image = $manager->create(5, 4); $image = $manager->create(5, 4);
$this->assertInstanceOf(ImageInterface::class, $image); $this->assertInstanceOf(ImageInterface::class, $image);
} }
@@ -62,7 +66,7 @@ class ImageManagerTest extends TestCase
/** @requires extension imagick */ /** @requires extension imagick */
public function testReadImagick() public function testReadImagick()
{ {
$manager = new ImageManager('imagick'); $manager = new ImageManager(ImagickDriver::class);
$image = $manager->read(__DIR__ . '/images/red.gif'); $image = $manager->read(__DIR__ . '/images/red.gif');
$this->assertInstanceOf(ImageInterface::class, $image); $this->assertInstanceOf(ImageInterface::class, $image);
} }

136
tests/ImageTest.php Normal file
View File

@@ -0,0 +1,136 @@
<?php
namespace Intervention\Image\Tests;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\EncodedImage;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\CollectionInterface;
use Intervention\Image\Interfaces\CoreInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Modifiers\GreyscaleModifier;
use Mockery;
class ImageTest extends TestCase
{
protected $modifier_mock;
protected $encoder_mock;
public function setUp(): void
{
$modifier = Mockery::mock(ModifierInterface::class);
$modifier->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);
}
}

View File

@@ -2,7 +2,7 @@
namespace Intervention\Image\Tests; 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\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\ModifierStack; use Intervention\Image\ModifierStack;

View File

@@ -2,16 +2,17 @@
namespace Intervention\Image\Tests\Traits; 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\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Drivers\Gd\Frame; use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\Drivers\Gd\Image; use Intervention\Image\Image;
trait CanCreateGdTestImage trait CanCreateGdTestImage
{ {
public function createTestImage($filename = 'test.jpg'): Image public function createTestImage($filename = 'test.jpg'): Image
{ {
return $this->createWithImageDecoder()->handle( return (new FilePathImageDecoder())->handle(
$this->getTestImagePath($filename) $this->getTestImagePath($filename)
); );
} }
@@ -24,15 +25,14 @@ trait CanCreateGdTestImage
imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0)); imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0));
$gd3 = imagecreatetruecolor(3, 2); $gd3 = imagecreatetruecolor(3, 2);
imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255)); 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 Image(
{ new Driver(),
return new FilePathImageDecoder(); new Core([
new Frame($gd1),
new Frame($gd2),
new Frame($gd3),
])
);
} }
} }

View File

@@ -3,19 +3,14 @@
namespace Intervention\Image\Tests\Traits; namespace Intervention\Image\Tests\Traits;
use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Imagick\Image; use Intervention\Image\Image;
trait CanCreateImagickTestImage trait CanCreateImagickTestImage
{ {
public function createTestImage($filename = 'test.jpg'): Image public function createTestImage($filename = 'test.jpg'): Image
{ {
return $this->createWithImageDecoder()->handle( return (new FilePathImageDecoder())->handle(
sprintf('%s/../images/%s', __DIR__, $filename) sprintf('%s/../images/%s', __DIR__, $filename)
); );
} }
protected function createWithImageDecoder(): FilePathImageDecoder
{
return new FilePathImageDecoder();
}
} }

View File

@@ -23,11 +23,11 @@ class LineTest extends TestCase
public function testSetGetPosition(): void public function testSetGetPosition(): void
{ {
$line = new Line('foo'); $line = new Line('foo');
$this->assertEquals(0, $line->getPosition()->x()); $this->assertEquals(0, $line->position()->x());
$this->assertEquals(0, $line->getPosition()->y()); $this->assertEquals(0, $line->position()->y());
$line->setPosition(new Point(10, 11)); $line->setPosition(new Point(10, 11));
$this->assertEquals(10, $line->getPosition()->x()); $this->assertEquals(10, $line->position()->x());
$this->assertEquals(11, $line->getPosition()->y()); $this->assertEquals(11, $line->position()->y());
} }
} }

View File

@@ -36,9 +36,9 @@ class TextBlockTest extends TestCase
public function testGetLine(): void public function testGetLine(): void
{ {
$block = $this->getTestBlock(); $block = $this->getTestBlock();
$this->assertEquals('foo', $block->getLine(0)); $this->assertEquals('foo', $block->line(0));
$this->assertEquals('FooBar', $block->getLine(1)); $this->assertEquals('FooBar', $block->line(1));
$this->assertEquals('bar', $block->getLine(2)); $this->assertEquals('bar', $block->line(2));
} }
public function testLongestLine(): void public function testLongestLine(): void
@@ -65,12 +65,12 @@ class TextBlockTest extends TestCase
); );
$font->shouldReceive('leadingInPixels')->andReturn(30); $font->shouldReceive('leadingInPixels')->andReturn(30);
$font->shouldReceive('getAlign')->andReturn('left'); $font->shouldReceive('alignment')->andReturn('left');
$font->shouldReceive('getValign')->andReturn('bottom'); $font->shouldReceive('valignment')->andReturn('bottom');
$font->shouldReceive('getAngle')->andReturn(0); $font->shouldReceive('angle')->andReturn(0);
$font->shouldReceive('capHeight')->andReturn(22); $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(300, $box->width());
$this->assertEquals(82, $box->height()); $this->assertEquals(82, $box->height());
$this->assertEquals(10, $box->pivot()->x()); $this->assertEquals(10, $box->pivot()->x());