mirror of
https://github.com/Intervention/image.git
synced 2025-08-11 16:34:00 +02:00
Added missing geometry tests
This commit is contained in:
@@ -5,43 +5,6 @@ namespace Intervention\Image\Geometry;
|
|||||||
use Intervention\Image\Geometry\Size;
|
use Intervention\Image\Geometry\Size;
|
||||||
use Intervention\Image\Interfaces\SizeInterface;
|
use Intervention\Image\Interfaces\SizeInterface;
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
modes: fill, contain, cover
|
|
||||||
resize($width, $height, $mode, $only_reduce)
|
|
||||||
resize(function($size) {
|
|
||||||
$size->width(300);
|
|
||||||
$size->contain();
|
|
||||||
$size->reduce();
|
|
||||||
});
|
|
||||||
|
|
||||||
- resize
|
|
||||||
- resizeDown
|
|
||||||
- scale
|
|
||||||
- scaleDown
|
|
||||||
- contain
|
|
||||||
- containDown
|
|
||||||
- cover
|
|
||||||
- coverDown
|
|
||||||
|
|
||||||
- resize
|
|
||||||
- resizeDown
|
|
||||||
- scale
|
|
||||||
- scaleDown
|
|
||||||
- fit(contain|cover)
|
|
||||||
- fitDown(contain|cover)
|
|
||||||
|
|
||||||
- resize
|
|
||||||
- resizeDown
|
|
||||||
- scale
|
|
||||||
- scaleDown
|
|
||||||
- fit
|
|
||||||
- fitDown
|
|
||||||
- pad
|
|
||||||
- padDown
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
class Resizer
|
class Resizer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@@ -29,6 +29,20 @@ class Size implements SizeInterface
|
|||||||
return $this->height;
|
return $this->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setWidth(int $width): SizeInterface
|
||||||
|
{
|
||||||
|
$this->width = $width;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHeight(int $height): SizeInterface
|
||||||
|
{
|
||||||
|
$this->height = $height;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current pivot point
|
* Get current pivot point
|
||||||
*
|
*
|
||||||
@@ -46,20 +60,6 @@ class Size implements SizeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setWidth(int $width): SizeInterface
|
|
||||||
{
|
|
||||||
$this->width = $width;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHeight(int $height): SizeInterface
|
|
||||||
{
|
|
||||||
$this->height = $height;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAspectRatio(): float
|
public function getAspectRatio(): float
|
||||||
{
|
{
|
||||||
return $this->width / $this->height;
|
return $this->width / $this->height;
|
||||||
|
@@ -23,7 +23,7 @@ class PointTest extends TestCase
|
|||||||
$this->assertEquals(50, $point->getY());
|
$this->assertEquals(50, $point->getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetX()
|
public function testGetSetX()
|
||||||
{
|
{
|
||||||
$point = new Point(0, 0);
|
$point = new Point(0, 0);
|
||||||
$point->setX(100);
|
$point->setX(100);
|
||||||
@@ -31,7 +31,7 @@ class PointTest extends TestCase
|
|||||||
$this->assertEquals(0, $point->getY());
|
$this->assertEquals(0, $point->getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetY()
|
public function testGetSetY()
|
||||||
{
|
{
|
||||||
$point = new Point(0, 0);
|
$point = new Point(0, 0);
|
||||||
$point->setY(100);
|
$point->setY(100);
|
||||||
|
@@ -9,6 +9,30 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class ResizerTest extends TestCase
|
class ResizerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
public function testMake(): void
|
||||||
|
{
|
||||||
|
$result = Resizer::make();
|
||||||
|
$this->assertInstanceOf(Resizer::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetTargetWidth(): void
|
||||||
|
{
|
||||||
|
$resizer = new Resizer();
|
||||||
|
$result = $resizer->width(100);
|
||||||
|
$this->assertInstanceOf(Resizer::class, $result);
|
||||||
|
$result = $resizer->toWidth(100);
|
||||||
|
$this->assertInstanceOf(Resizer::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetTargetHeight(): void
|
||||||
|
{
|
||||||
|
$resizer = new Resizer();
|
||||||
|
$result = $resizer->height(100);
|
||||||
|
$this->assertInstanceOf(Resizer::class, $result);
|
||||||
|
$result = $resizer->toHeight(100);
|
||||||
|
$this->assertInstanceOf(Resizer::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetTargetSizeByArray()
|
public function testSetTargetSizeByArray()
|
||||||
{
|
{
|
||||||
$size = new Size(300, 200);
|
$size = new Size(300, 200);
|
||||||
@@ -64,6 +88,16 @@ class ResizerTest extends TestCase
|
|||||||
$this->assertEquals(100, $resizer->resize($size)->getHeight());
|
$this->assertEquals(100, $resizer->resize($size)->getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testToSize(): void
|
||||||
|
{
|
||||||
|
$size = new Size(300, 200);
|
||||||
|
$resizer = new Resizer();
|
||||||
|
$resizer = $resizer->toSize(new Size(200, 100));
|
||||||
|
$this->assertInstanceOf(Resizer::class, $resizer);
|
||||||
|
$this->assertEquals(200, $resizer->resize($size)->getWidth());
|
||||||
|
$this->assertEquals(100, $resizer->resize($size)->getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
public function testResize()
|
public function testResize()
|
||||||
{
|
{
|
||||||
$size = new Size(300, 200);
|
$size = new Size(300, 200);
|
||||||
|
@@ -37,16 +37,33 @@ class SizeTest extends TestCase
|
|||||||
$this->assertFalse($size3 == $size4);
|
$this->assertFalse($size3 == $size4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetWidth()
|
public function testSetGetWidth()
|
||||||
{
|
{
|
||||||
$size = new Size(800, 600);
|
$size = new Size(800, 600);
|
||||||
$this->assertEquals(800, $size->getWidth());
|
$this->assertEquals(800, $size->getWidth());
|
||||||
|
$result = $size->setWidth(30);
|
||||||
|
$this->assertEquals(30, $size->getWidth());
|
||||||
|
$this->assertInstanceOf(Size::class, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetHeight()
|
public function testSetGetHeight()
|
||||||
{
|
{
|
||||||
$size = new Size(800, 600);
|
$size = new Size(800, 600);
|
||||||
$this->assertEquals(600, $size->getHeight());
|
$this->assertEquals(600, $size->getHeight());
|
||||||
|
$result = $size->setHeight(30);
|
||||||
|
$this->assertEquals(30, $size->getHeight());
|
||||||
|
$this->assertInstanceOf(Size::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetGetPivot(): void
|
||||||
|
{
|
||||||
|
$size = new Size(800, 600);
|
||||||
|
$pivot = $size->getPivot();
|
||||||
|
$this->assertInstanceOf(Point::class, $pivot);
|
||||||
|
$this->assertEquals(0, $pivot->getX());
|
||||||
|
$result = $size->setPivot(new Point(10, 0));
|
||||||
|
$this->assertInstanceOf(Size::class, $result);
|
||||||
|
$this->assertEquals(10, $size->getPivot()->getX());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAspectRatio()
|
public function testGetAspectRatio()
|
||||||
|
Reference in New Issue
Block a user