mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
Add analyzer tests
This commit is contained in:
@@ -1,451 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Abstract;
|
||||
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Drivers\Abstract\AbstractImage;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Geometry\Rectangle;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
* @covers \Intervention\Image\Drivers\Abstract\AbstractImage
|
||||
*/
|
||||
// class AbstractImageTest extends TestCase
|
||||
// {
|
||||
// protected function abstractImageMock(): AbstractImage
|
||||
// {
|
||||
// $frame1 = Mockery::mock(FrameInterface::class);
|
||||
// $frame1->shouldReceive('ident')->andReturn(1);
|
||||
// $frame2 = Mockery::mock(FrameInterface::class);
|
||||
// $frame2->shouldReceive('ident')->andReturn(2);
|
||||
// $frame3 = Mockery::mock(FrameInterface::class);
|
||||
// $frame3->shouldReceive('ident')->andReturn(3);
|
||||
//
|
||||
// $collection = new Collection([$frame1, $frame2, $frame3]);
|
||||
//
|
||||
// $mock = Mockery::mock(AbstractImage::class, ImageInterface::class)
|
||||
// ->shouldAllowMockingProtectedMethods()
|
||||
// ->makePartial();
|
||||
//
|
||||
// $mock->shouldReceive('width')->andReturn(300);
|
||||
// $mock->shouldReceive('height')->andReturn(200);
|
||||
// $mock->shouldReceive('getIterator')->andReturn($collection);
|
||||
//
|
||||
// return $mock;
|
||||
// }
|
||||
//
|
||||
// public function testGetSize(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
// $this->assertInstanceOf(Rectangle::class, $img->size());
|
||||
// $this->assertEquals(300, $img->size()->width());
|
||||
// $this->assertEquals(200, $img->size()->height());
|
||||
// }
|
||||
//
|
||||
// public function testSizeAlias(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
// $this->assertInstanceOf(Rectangle::class, $img->size());
|
||||
// $this->assertEquals(300, $img->size()->width());
|
||||
// $this->assertEquals(200, $img->size()->height());
|
||||
// }
|
||||
//
|
||||
// public function testModify(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
// $result = $img->modify($modifier);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $img);
|
||||
// }
|
||||
//
|
||||
// public function testEncode(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
// $result = $img->encode($encoder);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $img);
|
||||
// }
|
||||
//
|
||||
// public function testToJpeg(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\JpegEncoder', 45)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toJpeg(45);
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testToWebp(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\WebpEncoder', 45)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toWebp(45);
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testToGif(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\GifEncoder', 0)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toGif();
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testToPng(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\PngEncoder', 0)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toPng();
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testGreyscale(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\GreyscaleModifier')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->greyscale();
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testInvert(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\InvertModifier')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->invert();
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testBrightness(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\BrightnessModifier', 5)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->brightness(5);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testContrast(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ContrastModifier', 5)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->contrast(5);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testBlur(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\BlurModifier', 3)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->blur(3);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testRotate(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\RotateModifier', 3, 'cccccc')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->rotate(3, 'cccccc');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPlace(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->place('el', 'top-left', 0, 0);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testFill(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $color = Mockery::mock(ColorInterface::class);
|
||||
//
|
||||
// $img->shouldReceive('handleInput')
|
||||
// ->with('abcdef')
|
||||
// ->andReturn($color);
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\FillModifier', $color, null)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->fill('abcdef');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPixelate(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PixelateModifier', 42)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->pixelate(42);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testSharpen(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\SharpenModifier', 7)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->sharpen(7);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPickColors(): void
|
||||
// {
|
||||
// $color = Mockery::mock(ColorInterface::class);
|
||||
// $img = $this->abstractImageMock();
|
||||
// $img->shouldReceive('pickColor')->times(3)->andReturn($color);
|
||||
// $result = $img->pickColors(1, 2);
|
||||
// $this->assertInstanceOf(Collection::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testResize(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ResizeModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->resize(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testResizeDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ResizeDownModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->resizeDown(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testScale(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ScaleModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->scale(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testScaleDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ScaleDownModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->scaleDown(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testFit(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\FitModifier', 200, 100, 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->fit(200, 100, 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testFitDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\FitDownModifier', 200, 100, 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->fitDown(200, 100, 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPad(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->pad(200, 100, 'ffffff', 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPadDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->padDown(200, 100, 'ffffff', 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testSetGetExif(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
// $img->setExif((['test' => 'value']));
|
||||
//
|
||||
// $this->assertInstanceOf(Collection::class, $img->exif());
|
||||
// $this->assertEquals('value', $img->exif('test'));
|
||||
// }
|
||||
//
|
||||
// public function testDestroy(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\DestroyModifier')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $img->destroy();
|
||||
// }
|
||||
// }
|
29
tests/Drivers/DriverAnalyzerTest.php
Normal file
29
tests/Drivers/DriverAnalyzerTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers;
|
||||
|
||||
use Intervention\Image\Drivers\DriverAnalyzer;
|
||||
use Intervention\Image\Interfaces\AnalyzerInterface;
|
||||
use Intervention\Image\Interfaces\DriverInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Mockery;
|
||||
|
||||
/**
|
||||
* @covers \Intervention\Image\Drivers\DriverAnalyzer
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DriverAnalyzerTest extends TestCase
|
||||
{
|
||||
public function testDriver(): void
|
||||
{
|
||||
$analyzer = Mockery::mock(DriverAnalyzer::class, [
|
||||
Mockery::mock(AnalyzerInterface::class),
|
||||
Mockery::mock(DriverInterface::class)
|
||||
])->makePartial();
|
||||
|
||||
$this->assertInstanceOf(DriverInterface::class, $analyzer->driver());
|
||||
}
|
||||
}
|
21
tests/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php
Normal file
21
tests/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\ColorspaceAnalyzer;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
class ColorspaceAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new ColorspaceAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(ColorspaceInterface::class, $result);
|
||||
}
|
||||
}
|
20
tests/Drivers/Gd/Analyzers/HeightAnalyzerTest.php
Normal file
20
tests/Drivers/Gd/Analyzers/HeightAnalyzerTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\HeightAnalyzer;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
class HeightAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new HeightAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertEquals(16, $result);
|
||||
}
|
||||
}
|
22
tests/Drivers/Gd/Analyzers/PixelColorAnalyzer.php
Normal file
22
tests/Drivers/Gd/Analyzers/PixelColorAnalyzer.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\PixelColorAnalyzer;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
class PixelColorAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new PixelColorAnalyzer(0, 0);
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(ColorInterface::class, $result);
|
||||
$this->assertEquals('b4e000', $result->toHex());
|
||||
}
|
||||
}
|
24
tests/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php
Normal file
24
tests/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\PixelColorsAnalyzer;
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
class PixelColorsAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->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());
|
||||
}
|
||||
}
|
21
tests/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php
Normal file
21
tests/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\ResolutionAnalyzer;
|
||||
use Intervention\Image\Resolution;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
class ResolutionAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new ResolutionAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(Resolution::class, $result);
|
||||
}
|
||||
}
|
20
tests/Drivers/Gd/Analyzers/WidthAnalyzerTest.php
Normal file
20
tests/Drivers/Gd/Analyzers/WidthAnalyzerTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\WidthAnalyzer;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
class WidthAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new WidthAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertEquals(16, $result);
|
||||
}
|
||||
}
|
21
tests/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php
Normal file
21
tests/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\ColorspaceAnalyzer;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class ColorspaceAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new ColorspaceAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(ColorspaceInterface::class, $result);
|
||||
}
|
||||
}
|
20
tests/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php
Normal file
20
tests/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\HeightAnalyzer;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class HeightAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new HeightAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertEquals(16, $result);
|
||||
}
|
||||
}
|
22
tests/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php
Normal file
22
tests/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\PixelColorAnalyzer;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class PixelColorAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new PixelColorAnalyzer(0, 0);
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(ColorInterface::class, $result);
|
||||
$this->assertEquals('b4e000', $result->toHex());
|
||||
}
|
||||
}
|
24
tests/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php
Normal file
24
tests/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\PixelColorsAnalyzer;
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class PixelColorsAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->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());
|
||||
}
|
||||
}
|
21
tests/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php
Normal file
21
tests/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\ProfileAnalyzer;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class ProfleAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new ProfileAnalyzer();
|
||||
$this->expectException(ColorException::class);
|
||||
$analyzer->analyze($image);
|
||||
}
|
||||
}
|
21
tests/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php
Normal file
21
tests/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\ResolutionAnalyzer;
|
||||
use Intervention\Image\Resolution;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class ResolutionAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new ResolutionAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertInstanceOf(Resolution::class, $result);
|
||||
}
|
||||
}
|
20
tests/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php
Normal file
20
tests/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Analyzers;
|
||||
|
||||
use Intervention\Image\Analyzers\WidthAnalyzer;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
class WidthAnalyzerTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testAnalyze(): void
|
||||
{
|
||||
$image = $this->createTestImage('tile.png');
|
||||
$analyzer = new WidthAnalyzer();
|
||||
$result = $analyzer->analyze($image);
|
||||
$this->assertEquals(16, $result);
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Traits;
|
||||
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
|
||||
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
|
||||
use Intervention\Image\Colors\Rgb\Color as RgbColor;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @requires extension imagick
|
||||
* @covers \Intervention\Image\Drivers\Imagick\Traits\CanHandleColors
|
||||
*/
|
||||
class CanHandleColorsTest extends TestCase
|
||||
{
|
||||
protected function getAnonymousTrait()
|
||||
{
|
||||
return new class()
|
||||
{
|
||||
use CanHandleColors;
|
||||
};
|
||||
}
|
||||
|
||||
public function testColorFromPixel(): void
|
||||
{
|
||||
$result = $this->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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user