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

Add geometry factory tests

This commit is contained in:
Oliver Vogel
2024-01-15 11:50:10 +01:00
parent a5243592ac
commit 329c89164c
5 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace Intervention\Image\Tests\Geometry\Factories;
use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Geometry\Factories\CircleFactory;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Tests\TestCase;
class CircleFactoryTest extends TestCase
{
public function testFactoryCallback(): void
{
$factory = new CircleFactory(new Point(1, 2), function ($circle) {
$circle->background('fff');
$circle->border('ccc', 10);
$circle->radius(100);
$circle->diameter(1000);
});
$circle = $factory();
$this->assertInstanceOf(Ellipse::class, $circle);
$this->assertTrue($circle->hasBackgroundColor());
$this->assertEquals('fff', $circle->backgroundColor());
$this->assertEquals('ccc', $circle->borderColor());
$this->assertEquals(10, $circle->borderSize());
$this->assertEquals(1000, $circle->width());
$this->assertEquals(1000, $circle->height());
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Intervention\Image\Tests\Geometry\Factories;
use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Geometry\Factories\EllipseFactory;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Tests\TestCase;
class EllipseFactoryTest extends TestCase
{
public function testFactoryCallback(): void
{
$factory = new EllipseFactory(new Point(1, 2), function ($ellipse) {
$ellipse->background('fff');
$ellipse->border('ccc', 10);
$ellipse->width(100);
$ellipse->height(200);
$ellipse->size(1000, 2000);
});
$ellipse = $factory();
$this->assertInstanceOf(Ellipse::class, $ellipse);
$this->assertTrue($ellipse->hasBackgroundColor());
$this->assertEquals('fff', $ellipse->backgroundColor());
$this->assertEquals('ccc', $ellipse->borderColor());
$this->assertEquals(10, $ellipse->borderSize());
$this->assertEquals(1000, $ellipse->width());
$this->assertEquals(2000, $ellipse->height());
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Intervention\Image\Tests\Geometry\Factories;
use Intervention\Image\Geometry\Factories\LineFactory;
use Intervention\Image\Geometry\Line;
use Intervention\Image\Tests\TestCase;
class LineFactoryTest extends TestCase
{
public function testFactoryCallback(): void
{
$factory = new LineFactory(function ($line) {
$line->color('fff');
$line->background('fff');
$line->border('fff', 10);
$line->width(10);
$line->from(100, 200);
$line->to(300, 400);
});
$line = $factory();
$this->assertInstanceOf(Line::class, $line);
$this->assertTrue($line->hasBackgroundColor());
$this->assertEquals('fff', $line->backgroundColor());
$this->assertEquals(100, $line->start()->x());
$this->assertEquals(200, $line->start()->y());
$this->assertEquals(300, $line->end()->x());
$this->assertEquals(400, $line->end()->y());
$this->assertEquals(10, $line->width());
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Intervention\Image\Tests\Geometry\Factories;
use Intervention\Image\Geometry\Factories\PolygonFactory;
use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Tests\TestCase;
class PolygonFactoryTest extends TestCase
{
public function testFactoryCallback(): void
{
$factory = new PolygonFactory(function ($polygon) {
$polygon->background('fff');
$polygon->border('ccc', 10);
$polygon->point(1, 2);
$polygon->point(3, 4);
$polygon->point(5, 6);
});
$polygon = $factory();
$this->assertInstanceOf(Polygon::class, $polygon);
$this->assertTrue($polygon->hasBackgroundColor());
$this->assertEquals('fff', $polygon->backgroundColor());
$this->assertEquals('ccc', $polygon->borderColor());
$this->assertEquals(10, $polygon->borderSize());
$this->assertEquals(3, $polygon->count());
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Intervention\Image\Tests\Geometry\Factories;
use Intervention\Image\Geometry\Factories\RectangleFactory;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Tests\TestCase;
class RectangleFactoryTest extends TestCase
{
public function testFactoryCallback(): void
{
$factory = new RectangleFactory(new Point(1, 2), function ($rectangle) {
$rectangle->background('fff');
$rectangle->border('ccc', 10);
$rectangle->width(100);
$rectangle->height(200);
$rectangle->size(1000, 2000);
});
$rectangle = $factory();
$this->assertInstanceOf(Rectangle::class, $rectangle);
$this->assertTrue($rectangle->hasBackgroundColor());
$this->assertEquals('fff', $rectangle->backgroundColor());
$this->assertEquals('ccc', $rectangle->borderColor());
$this->assertEquals(10, $rectangle->borderSize());
$this->assertEquals(1000, $rectangle->width());
$this->assertEquals(2000, $rectangle->height());
}
}