1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 17:41:58 +02:00

PHPUnit 10 Migration (#1302)

* Bump PHPUnit dependencies

* Set return type of base TestCase methods

From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type:

- `setUpBeforeClass()`
- `setUp()`
- `assertPreConditions()`
- `assertPostConditions()`
- `tearDown()`
- `tearDownAfterClass()`
- `onNotSuccessfulTest()`

[1]: https://phpunit.de/announcements/phpunit-8.html

* Ignore PHPUnit cache folder

* Adopt PHP attributes in test classes

* Declare data providers as `static`

* Add return types to test methods

* Define test classes as `final`

* Migrate phpunit.xml to phpunit 10

* Correct phpunit attribute class name

* Rename base test class

* Restructure test folders

* Fix test image paths

* Only set rules for php files in .editorconfig

* Remove php unit flag in local test env

---------

Co-authored-by: Shift <shift@laravelshift.com>
This commit is contained in:
Oliver Vogel
2024-02-28 16:16:23 +01:00
committed by GitHub
parent fe1b0e2e64
commit dcc95b8299
183 changed files with 1347 additions and 1392 deletions

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Typography;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Typography\Font;
use Intervention\Image\Typography\FontFactory;
final class FontFactoryTest extends BaseTestCase
{
public function testBuildWithFont(): void
{
$factory = new FontFactory(new Font('foo.ttf'));
$result = $factory();
$this->assertInstanceOf(FontInterface::class, $result);
$this->assertEquals('foo.ttf', $result->filename());
}
public function testBuildWithCallback(): void
{
$factory = new FontFactory(function ($font) {
$font->filename('foo.ttf');
$font->file('bar.ttf');
$font->color('#b01735');
$font->size(70);
$font->align('center');
$font->valign('middle');
$font->lineHeight(1.6);
$font->angle(10);
});
$result = $factory();
$this->assertInstanceOf(FontInterface::class, $result);
$this->assertEquals('bar.ttf', $result->filename());
$this->assertEquals('#b01735', $result->color());
$this->assertEquals(70, $result->size());
$this->assertEquals('center', $result->alignment());
$this->assertEquals('middle', $result->valignment());
$this->assertEquals(1.6, $result->lineHeight());
$this->assertEquals(10, $result->angle());
}
}

View File

@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Typography;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Typography\Font;
final class FontTest extends BaseTestCase
{
public function testConstructor(): void
{
$font = new Font('foo.ttf');
$this->assertInstanceOf(Font::class, $font);
$this->assertEquals('foo.ttf', $font->filename());
}
public function testSetGetSize(): void
{
$font = new Font();
$this->assertEquals(12, $font->size());
$result = $font->setSize(123);
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals(123, $font->size());
}
public function testSetGetAngle(): void
{
$font = new Font();
$this->assertEquals(0, $font->angle());
$result = $font->setAngle(123);
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals(123, $font->angle());
}
public function testSetGetFilename(): void
{
$font = new Font();
$this->assertEquals(null, $font->filename());
$this->assertFalse($font->hasFilename());
$filename = $this->getTestImagePath();
$result = $font->setFilename($filename);
$this->assertTrue($font->hasFilename());
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals($filename, $font->filename());
}
public function testSetGetColor(): void
{
$font = new Font();
$this->assertEquals('000000', $font->color());
$result = $font->setColor('fff');
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals('fff', $font->color());
}
public function testSetGetAlignment(): void
{
$font = new Font();
$this->assertEquals('left', $font->alignment());
$result = $font->setAlignment('center');
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals('center', $font->alignment());
}
public function testSetGetValignment(): void
{
$font = new Font();
$this->assertEquals('bottom', $font->valignment());
$result = $font->setValignment('center');
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals('center', $font->valignment());
}
public function testSetGetLineHeight(): void
{
$font = new Font();
$this->assertEquals(1.25, $font->lineHeight());
$result = $font->setLineHeight(3.2);
$this->assertInstanceOf(Font::class, $result);
$this->assertEquals(3.2, $font->lineHeight());
}
}

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Typography;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Typography\Line;
final class LineTest extends BaseTestCase
{
public function testConstructor(): void
{
$line = new Line('foo');
$this->assertInstanceOf(Line::class, $line);
}
public function testToString(): void
{
$line = new Line('foo bar');
$this->assertEquals('foo bar', (string) $line);
}
public function testSetGetPosition(): void
{
$line = new Line('foo');
$this->assertEquals(0, $line->position()->x());
$this->assertEquals(0, $line->position()->y());
$line->setPosition(new Point(10, 11));
$this->assertEquals(10, $line->position()->x());
$this->assertEquals(11, $line->position()->y());
}
public function testCount(): void
{
$line = new Line();
$this->assertEquals(0, $line->count());
$line = new Line("foo");
$this->assertEquals(1, $line->count());
$line = new Line("foo bar");
$this->assertEquals(2, $line->count());
}
public function testAdd(): void
{
$line = new Line();
$this->assertEquals(0, $line->count());
$result = $line->add('foo');
$this->assertEquals(1, $line->count());
$this->assertEquals(1, $result->count());
$result = $line->add('bar');
$this->assertEquals(2, $line->count());
$this->assertEquals(2, $result->count());
}
}

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Typography;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Typography\TextBlock;
final class TextBlockTest extends BaseTestCase
{
protected TextBlock $block;
protected function setUp(): void
{
$this->block = new TextBlock(<<<EOF
foo
FooBar
bar
EOF);
}
public function testCount(): void
{
$this->assertEquals(3, $this->block->count());
}
public function testLines(): void
{
$this->assertCount(3, $this->block->lines());
}
public function testGetLine(): void
{
$this->assertEquals('foo', $this->block->line(0));
$this->assertEquals('FooBar', $this->block->line(1));
$this->assertEquals('bar', $this->block->line(2));
$this->assertNull($this->block->line(20));
}
public function testLongestLine(): void
{
$result = $this->block->longestLine();
$this->assertEquals('FooBar', (string) $result);
}
}