mirror of
https://github.com/Intervention/image.git
synced 2025-08-25 23:06:13 +02:00
Add type hints in tests
This commit is contained in:
@@ -16,17 +16,17 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
abstract class BaseTestCase extends MockeryTestCase
|
||||
{
|
||||
public static function getTestResourcePath($filename = 'test.jpg'): string
|
||||
public static function getTestResourcePath(string $filename = 'test.jpg'): string
|
||||
{
|
||||
return sprintf('%s/resources/%s', __DIR__, $filename);
|
||||
}
|
||||
|
||||
public static function getTestResourceData($filename = 'test.jpg'): string
|
||||
public static function getTestResourceData(string $filename = 'test.jpg'): string
|
||||
{
|
||||
return file_get_contents(self::getTestResourcePath($filename));
|
||||
}
|
||||
|
||||
public static function getTestResourcePointer($filename = 'test.jpg')
|
||||
public static function getTestResourcePointer(string $filename = 'test.jpg'): mixed
|
||||
{
|
||||
$pointer = fopen('php://temp', 'rw');
|
||||
fwrite($pointer, self::getTestResourceData($filename));
|
||||
@@ -39,9 +39,8 @@ abstract class BaseTestCase extends MockeryTestCase
|
||||
* Assert that given color equals the given color channel values in the given optional tolerance
|
||||
*
|
||||
* @throws ExpectationFailedException
|
||||
* @return void
|
||||
*/
|
||||
protected function assertColor(int $r, int $g, int $b, int $a, ColorInterface $color, int $tolerance = 0)
|
||||
protected function assertColor(int $r, int $g, int $b, int $a, ColorInterface $color, int $tolerance = 0): void
|
||||
{
|
||||
// build errorMessage
|
||||
$errorMessage = function (int $r, int $g, $b, int $a, ColorInterface $color): string {
|
||||
@@ -90,7 +89,7 @@ abstract class BaseTestCase extends MockeryTestCase
|
||||
);
|
||||
}
|
||||
|
||||
protected function assertTransparency(ColorInterface $color)
|
||||
protected function assertTransparency(ColorInterface $color): void
|
||||
{
|
||||
$this->assertInstanceOf(RgbColor::class, $color);
|
||||
$channel = $color->channel(Alpha::class);
|
||||
|
@@ -12,7 +12,7 @@ use Intervention\Image\Image;
|
||||
|
||||
abstract class GdTestCase extends BaseTestCase
|
||||
{
|
||||
public static function readTestImage($filename = 'test.jpg'): Image
|
||||
public static function readTestImage(string $filename = 'test.jpg'): Image
|
||||
{
|
||||
return (new Driver())->specialize(new FilePathImageDecoder())->decode(
|
||||
static::getTestResourcePath($filename)
|
||||
|
@@ -14,7 +14,7 @@ use Intervention\Image\Image;
|
||||
|
||||
abstract class ImagickTestCase extends BaseTestCase
|
||||
{
|
||||
public static function readTestImage($filename = 'test.jpg'): Image
|
||||
public static function readTestImage(string $filename = 'test.jpg'): Image
|
||||
{
|
||||
return (new Driver())->specialize(new FilePathImageDecoder())->decode(
|
||||
static::getTestResourcePath($filename)
|
||||
|
@@ -14,6 +14,9 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(StringColorDecoder::class)]
|
||||
final class StringColorDecoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $channelValues array<int>
|
||||
*/
|
||||
#[DataProvider('decodeDataProvier')]
|
||||
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||
{
|
||||
|
@@ -14,6 +14,9 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(StringColorDecoder::class)]
|
||||
final class StringColorDecoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $channelValues array<int>
|
||||
*/
|
||||
#[DataProvider('decodeDataProvier')]
|
||||
public function testDecodeHsv(string $input, string $classname, array $channelValues): void
|
||||
{
|
||||
|
@@ -14,6 +14,9 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(HexColorDecoder::class)]
|
||||
final class HexColorDecoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $channelValues array<int>
|
||||
*/
|
||||
#[DataProvider('decodeDataProvier')]
|
||||
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||
{
|
||||
|
@@ -14,6 +14,9 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(HtmlColorNameDecoder::class)]
|
||||
final class HtmlColornameDecoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $channelValues array<int>
|
||||
*/
|
||||
#[DataProvider('decodeDataProvier')]
|
||||
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||
{
|
||||
|
@@ -14,6 +14,9 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(StringColorDecoder::class)]
|
||||
final class StringColorDecoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $channelValues array<int>
|
||||
*/
|
||||
#[DataProvider('decodeDataProvier')]
|
||||
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||
{
|
||||
|
@@ -45,7 +45,7 @@ final class DriverTest extends BaseTestCase
|
||||
|
||||
public function testCreateAnimation(): void
|
||||
{
|
||||
$image = $this->driver->createAnimation(function ($animation) {
|
||||
$image = $this->driver->createAnimation(function ($animation): void {
|
||||
$animation->add($this->getTestResourcePath('red.gif'), .25);
|
||||
$animation->add($this->getTestResourcePath('green.gif'), .25);
|
||||
})->setLoops(5);
|
||||
|
@@ -24,7 +24,7 @@ final class TextModifierTest extends GdTestCase
|
||||
|
||||
$modifier = new class ('test', new Point(), $font) extends TextModifier
|
||||
{
|
||||
public function test()
|
||||
public function test(): ColorInterface
|
||||
{
|
||||
return $this->textColor();
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ final class DriverTest extends BaseTestCase
|
||||
|
||||
public function testCreateAnimation(): void
|
||||
{
|
||||
$image = $this->driver->createAnimation(function ($animation) {
|
||||
$image = $this->driver->createAnimation(function ($animation): void {
|
||||
$animation->add($this->getTestResourcePath('red.gif'), .25);
|
||||
$animation->add($this->getTestResourcePath('green.gif'), .25);
|
||||
})->setLoops(5);
|
||||
|
@@ -24,7 +24,7 @@ final class TextModifierTest extends ImagickTestCase
|
||||
|
||||
$modifier = new class ('test', new Point(), $font) extends TextModifier
|
||||
{
|
||||
public function test()
|
||||
public function test(): ColorInterface
|
||||
{
|
||||
return $this->textColor();
|
||||
}
|
||||
|
@@ -25,16 +25,19 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(FileExtensionEncoder::class)]
|
||||
final class FileExtensionEncoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $options array<string, int>
|
||||
*/
|
||||
private function testEncoder(string|FileExtension $extension, array $options = []): EncoderInterface
|
||||
{
|
||||
$encoder = new class ($extension, ...$options) extends FileExtensionEncoder
|
||||
{
|
||||
public function __construct($mediaType, ...$options)
|
||||
public function __construct(string|FileExtension $extension, mixed ...$options)
|
||||
{
|
||||
parent::__construct($mediaType, ...$options);
|
||||
parent::__construct($extension, ...$options);
|
||||
}
|
||||
|
||||
public function test($extension)
|
||||
public function test(string|FileExtension $extension): EncoderInterface
|
||||
{
|
||||
return $this->encoderByFileExtension($extension);
|
||||
}
|
||||
|
@@ -25,16 +25,19 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
||||
#[CoversClass(MediaTypeEncoder::class)]
|
||||
final class MediaTypeEncoderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $options array<string, int>
|
||||
*/
|
||||
private function testEncoder(string|MediaType $mediaType, array $options = []): EncoderInterface
|
||||
{
|
||||
$encoder = new class ($mediaType, ...$options) extends MediaTypeEncoder
|
||||
{
|
||||
public function __construct($mediaType, ...$options)
|
||||
public function __construct(string|MediaType $mediaType, mixed ...$options)
|
||||
{
|
||||
parent::__construct($mediaType, ...$options);
|
||||
}
|
||||
|
||||
public function test($mediaType)
|
||||
public function test(string|MediaType $mediaType): EncoderInterface
|
||||
{
|
||||
return $this->encoderByMediaType($mediaType);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ final class BezierFactoryTest extends BaseTestCase
|
||||
{
|
||||
public function testFactoryCallback(): void
|
||||
{
|
||||
$factory = new BezierFactory(function ($bezier) {
|
||||
$factory = new BezierFactory(function ($bezier): void {
|
||||
$bezier->background('f00');
|
||||
$bezier->border('ff0', 10);
|
||||
$bezier->point(300, 260);
|
||||
|
@@ -15,7 +15,7 @@ final class CircleFactoryTest extends BaseTestCase
|
||||
{
|
||||
public function testFactoryCallback(): void
|
||||
{
|
||||
$factory = new CircleFactory(new Point(1, 2), function ($circle) {
|
||||
$factory = new CircleFactory(new Point(1, 2), function ($circle): void {
|
||||
$circle->background('fff');
|
||||
$circle->border('ccc', 10);
|
||||
$circle->radius(100);
|
||||
|
@@ -15,7 +15,7 @@ final class EllipseFactoryTest extends BaseTestCase
|
||||
{
|
||||
public function testFactoryCallback(): void
|
||||
{
|
||||
$factory = new EllipseFactory(new Point(1, 2), function ($ellipse) {
|
||||
$factory = new EllipseFactory(new Point(1, 2), function ($ellipse): void {
|
||||
$ellipse->background('fff');
|
||||
$ellipse->border('ccc', 10);
|
||||
$ellipse->width(100);
|
||||
|
@@ -14,7 +14,7 @@ final class LineFactoryTest extends BaseTestCase
|
||||
{
|
||||
public function testFactoryCallback(): void
|
||||
{
|
||||
$factory = new LineFactory(function ($line) {
|
||||
$factory = new LineFactory(function ($line): void {
|
||||
$line->color('fff');
|
||||
$line->background('fff');
|
||||
$line->border('fff', 10);
|
||||
|
@@ -14,7 +14,7 @@ final class PolygonFactoryTest extends BaseTestCase
|
||||
{
|
||||
public function testFactoryCallback(): void
|
||||
{
|
||||
$factory = new PolygonFactory(function ($polygon) {
|
||||
$factory = new PolygonFactory(function ($polygon): void {
|
||||
$polygon->background('fff');
|
||||
$polygon->border('ccc', 10);
|
||||
$polygon->point(1, 2);
|
||||
|
@@ -15,7 +15,7 @@ final class RectangleFactoryTest extends BaseTestCase
|
||||
{
|
||||
public function testFactoryCallback(): void
|
||||
{
|
||||
$factory = new RectangleFactory(new Point(1, 2), function ($rectangle) {
|
||||
$factory = new RectangleFactory(new Point(1, 2), function ($rectangle): void {
|
||||
$rectangle->background('fff');
|
||||
$rectangle->border('ccc', 10);
|
||||
$rectangle->width(100);
|
||||
|
@@ -51,6 +51,9 @@ final class RectangleResizerTest extends TestCase
|
||||
$this->assertInstanceOf(RectangleResizer::class, $resizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resizeParameters array<string, int>
|
||||
*/
|
||||
#[DataProvider('resizeDataProvider')]
|
||||
public function testResize(Rectangle $input, array $resizeParameters, Rectangle $result): void
|
||||
{
|
||||
@@ -68,6 +71,9 @@ final class RectangleResizerTest extends TestCase
|
||||
yield [new Rectangle(300, 200), [], new Rectangle(300, 200)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resizeParameters array<string, int>
|
||||
*/
|
||||
#[DataProvider('resizeDownDataProvider')]
|
||||
public function testResizeDown(Rectangle $input, array $resizeParameters, Rectangle $result): void
|
||||
{
|
||||
@@ -88,6 +94,9 @@ final class RectangleResizerTest extends TestCase
|
||||
yield [new Rectangle(800, 600), [], new Rectangle(800, 600)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resizeParameters array<string, int>
|
||||
*/
|
||||
#[DataProvider('scaleDataProvider')]
|
||||
public function testScale(Rectangle $input, array $resizeParameters, Rectangle $result): void
|
||||
{
|
||||
@@ -119,6 +128,9 @@ final class RectangleResizerTest extends TestCase
|
||||
yield [new Rectangle(800, 600), [], new Rectangle(800, 600)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resizeParameters array<string, int>
|
||||
*/
|
||||
#[DataProvider('scaleDownDataProvider')]
|
||||
public function testScaleDown(Rectangle $input, array $resizeParameters, Rectangle $result): void
|
||||
{
|
||||
|
@@ -58,7 +58,7 @@ final class ImageManagerTestGd extends BaseTestCase
|
||||
public function testAnimate(): void
|
||||
{
|
||||
$manager = new ImageManager(Driver::class);
|
||||
$image = $manager->animate(function ($animation) {
|
||||
$image = $manager->animate(function ($animation): void {
|
||||
$animation->add($this->getTestResourcePath('red.gif'), .25);
|
||||
});
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
|
@@ -58,7 +58,7 @@ final class ImageManagerTestImagick extends BaseTestCase
|
||||
public function testAnimate(): void
|
||||
{
|
||||
$manager = new ImageManager(Driver::class);
|
||||
$image = $manager->animate(function ($animation) {
|
||||
$image = $manager->animate(function ($animation): void {
|
||||
$animation->add($this->getTestResourcePath('red.gif'), .25);
|
||||
});
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
|
@@ -18,7 +18,10 @@ final class TextModifierTest extends BaseTestCase
|
||||
{
|
||||
$modifier = new class ('test', new Point(), new Font()) extends TextModifier
|
||||
{
|
||||
public function testStrokeOffsets(FontInterface $font)
|
||||
/**
|
||||
* @return array<?Point>
|
||||
*/
|
||||
public function testStrokeOffsets(FontInterface $font): array
|
||||
{
|
||||
return $this->strokeOffsets($font);
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ final class FontFactoryTest extends BaseTestCase
|
||||
|
||||
public function testBuildWithCallback(): void
|
||||
{
|
||||
$factory = new FontFactory(function (FontFactory $font) {
|
||||
$factory = new FontFactory(function (FontFactory $font): void {
|
||||
$font->filename($this->getTestResourcePath('test.ttf'));
|
||||
$font->color('#b01735');
|
||||
$font->size(70);
|
||||
|
Reference in New Issue
Block a user