diff --git a/tests/Drivers/AbstractImageTest.php b/tests/Drivers/AbstractImageTest.php deleted file mode 100644 index d790c29e..00000000 --- a/tests/Drivers/AbstractImageTest.php +++ /dev/null @@ -1,451 +0,0 @@ -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/DriverAnalyzerTest.php b/tests/Drivers/DriverAnalyzerTest.php new file mode 100644 index 00000000..dae5e18e --- /dev/null +++ b/tests/Drivers/DriverAnalyzerTest.php @@ -0,0 +1,29 @@ +makePartial(); + + $this->assertInstanceOf(DriverInterface::class, $analyzer->driver()); + } +} diff --git a/tests/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php b/tests/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php new file mode 100644 index 00000000..c9303f51 --- /dev/null +++ b/tests/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php @@ -0,0 +1,21 @@ +createTestImage('tile.png'); + $analyzer = new ColorspaceAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(ColorspaceInterface::class, $result); + } +} diff --git a/tests/Drivers/Gd/Analyzers/HeightAnalyzerTest.php b/tests/Drivers/Gd/Analyzers/HeightAnalyzerTest.php new file mode 100644 index 00000000..0a189508 --- /dev/null +++ b/tests/Drivers/Gd/Analyzers/HeightAnalyzerTest.php @@ -0,0 +1,20 @@ +createTestImage('tile.png'); + $analyzer = new HeightAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertEquals(16, $result); + } +} diff --git a/tests/Drivers/Gd/Analyzers/PixelColorAnalyzer.php b/tests/Drivers/Gd/Analyzers/PixelColorAnalyzer.php new file mode 100644 index 00000000..782c4db8 --- /dev/null +++ b/tests/Drivers/Gd/Analyzers/PixelColorAnalyzer.php @@ -0,0 +1,22 @@ +createTestImage('tile.png'); + $analyzer = new PixelColorAnalyzer(0, 0); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(ColorInterface::class, $result); + $this->assertEquals('b4e000', $result->toHex()); + } +} diff --git a/tests/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php b/tests/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php new file mode 100644 index 00000000..f2e0c2ef --- /dev/null +++ b/tests/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php @@ -0,0 +1,24 @@ +createTestImage('tile.png'); + $analyzer = new PixelColorsAnalyzer(0, 0); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(Collection::class, $result); + $this->assertInstanceOf(ColorInterface::class, $result->first()); + $this->assertEquals('b4e000', $result->first()->toHex()); + } +} diff --git a/tests/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php b/tests/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php new file mode 100644 index 00000000..630467b9 --- /dev/null +++ b/tests/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php @@ -0,0 +1,21 @@ +createTestImage('tile.png'); + $analyzer = new ResolutionAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(Resolution::class, $result); + } +} diff --git a/tests/Drivers/Gd/Analyzers/WidthAnalyzerTest.php b/tests/Drivers/Gd/Analyzers/WidthAnalyzerTest.php new file mode 100644 index 00000000..50e416f6 --- /dev/null +++ b/tests/Drivers/Gd/Analyzers/WidthAnalyzerTest.php @@ -0,0 +1,20 @@ +createTestImage('tile.png'); + $analyzer = new WidthAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertEquals(16, $result); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php b/tests/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php new file mode 100644 index 00000000..70336818 --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php @@ -0,0 +1,21 @@ +createTestImage('tile.png'); + $analyzer = new ColorspaceAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(ColorspaceInterface::class, $result); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php b/tests/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php new file mode 100644 index 00000000..479e8578 --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php @@ -0,0 +1,20 @@ +createTestImage('tile.png'); + $analyzer = new HeightAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertEquals(16, $result); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php b/tests/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php new file mode 100644 index 00000000..993055a9 --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php @@ -0,0 +1,22 @@ +createTestImage('tile.png'); + $analyzer = new PixelColorAnalyzer(0, 0); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(ColorInterface::class, $result); + $this->assertEquals('b4e000', $result->toHex()); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php b/tests/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php new file mode 100644 index 00000000..043ee7fc --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php @@ -0,0 +1,24 @@ +createTestImage('tile.png'); + $analyzer = new PixelColorsAnalyzer(0, 0); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(Collection::class, $result); + $this->assertInstanceOf(ColorInterface::class, $result->first()); + $this->assertEquals('b4e000', $result->first()->toHex()); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php b/tests/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php new file mode 100644 index 00000000..42e5925f --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php @@ -0,0 +1,21 @@ +createTestImage('tile.png'); + $analyzer = new ProfileAnalyzer(); + $this->expectException(ColorException::class); + $analyzer->analyze($image); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php b/tests/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php new file mode 100644 index 00000000..14f77c97 --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php @@ -0,0 +1,21 @@ +createTestImage('tile.png'); + $analyzer = new ResolutionAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertInstanceOf(Resolution::class, $result); + } +} diff --git a/tests/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php b/tests/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php new file mode 100644 index 00000000..f8532302 --- /dev/null +++ b/tests/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php @@ -0,0 +1,20 @@ +createTestImage('tile.png'); + $analyzer = new WidthAnalyzer(); + $result = $analyzer->analyze($image); + $this->assertEquals(16, $result); + } +} diff --git a/tests/Drivers/Imagick/Traits/CanHandleColorsTest.php b/tests/Drivers/Imagick/Traits/CanHandleColorsTest.php deleted file mode 100644 index f9c66411..00000000 --- a/tests/Drivers/Imagick/Traits/CanHandleColorsTest.php +++ /dev/null @@ -1,58 +0,0 @@ -getAnonymousTrait() - ->pixelToColor(new ImagickPixel(), new RgbColorspace()); - $this->assertInstanceOf(RgbColor::class, $result); - - $result = $this->getAnonymousTrait() - ->pixelToColor(new ImagickPixel('rgba(10, 20, 30, .2)'), new RgbColorspace()); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals([10, 20, 30, 51], $result->toArray()); - - $result = $this->getAnonymousTrait() - ->pixelToColor(new ImagickPixel('cmyk(10%, 20%, 30%, 40%)'), new CmykColorspace()); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals([10, 20, 30, 40], $result->toArray()); - } - - public function testColorToPixel(): void - { - $result = $this->getAnonymousTrait()->colorToPixel(new RgbColor(10, 20, 30), new RgbColorspace()); - $this->assertInstanceOf(ImagickPixel::class, $result); - $this->assertEquals('srgb(10,20,30)', $result->getColorAsString()); - - $result = $this->getAnonymousTrait()->colorToPixel(new CmykColor(100, 50, 25, 0), new CmykColorspace()); - $this->assertInstanceOf(ImagickPixel::class, $result); - $this->assertEquals(1, $result->getColorValue(Imagick::COLOR_CYAN)); - $this->assertEquals(.5, round($result->getColorValue(Imagick::COLOR_MAGENTA), 2)); - $this->assertEquals(.25, round($result->getColorValue(Imagick::COLOR_YELLOW), 2)); - $this->assertEquals(0, $result->getColorValue(Imagick::COLOR_BLACK)); - } -}