mirror of
https://github.com/Intervention/image.git
synced 2025-08-22 13:32:56 +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:
79
tests/Unit/Encoders/FileExtensionEncoderTest.php
Normal file
79
tests/Unit/Encoders/FileExtensionEncoderTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Encoders;
|
||||
|
||||
use Intervention\Image\Encoders\AvifEncoder;
|
||||
use Intervention\Image\Encoders\BmpEncoder;
|
||||
use Intervention\Image\Encoders\FileExtensionEncoder;
|
||||
use Intervention\Image\Encoders\GifEncoder;
|
||||
use Intervention\Image\Encoders\HeicEncoder;
|
||||
use Intervention\Image\Encoders\Jpeg2000Encoder;
|
||||
use Intervention\Image\Encoders\JpegEncoder;
|
||||
use Intervention\Image\Encoders\PngEncoder;
|
||||
use Intervention\Image\Encoders\TiffEncoder;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\Exceptions\EncoderException;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Mockery;
|
||||
|
||||
final class FileExtensionEncoderTest extends BaseTestCase
|
||||
{
|
||||
public function testEncoderByFileExtension(): void
|
||||
{
|
||||
$encoder = Mockery::mock(FileExtensionEncoder::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
WebpEncoder::class,
|
||||
$encoder->encoderByFileExtension('webp')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
AvifEncoder::class,
|
||||
$encoder->encoderByFileExtension('avif')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
JpegEncoder::class,
|
||||
$encoder->encoderByFileExtension('jpeg')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
BmpEncoder::class,
|
||||
$encoder->encoderByFileExtension('bmp')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
GifEncoder::class,
|
||||
$encoder->encoderByFileExtension('gif')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
PngEncoder::class,
|
||||
$encoder->encoderByFileExtension('png')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
TiffEncoder::class,
|
||||
$encoder->encoderByFileExtension('tiff')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Jpeg2000Encoder::class,
|
||||
$encoder->encoderByFileExtension('jp2')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
HeicEncoder::class,
|
||||
$encoder->encoderByFileExtension('heic')
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncoderByFileExtensionUnknown(): void
|
||||
{
|
||||
$encoder = Mockery::mock(FileExtensionEncoder::class);
|
||||
$this->expectException(EncoderException::class);
|
||||
$encoder->encoderByFileExtension('test');
|
||||
}
|
||||
}
|
52
tests/Unit/Encoders/SpecializableEncoderTest.php
Normal file
52
tests/Unit/Encoders/SpecializableEncoderTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Encoders\SpecializableEncoder;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
use Mockery;
|
||||
|
||||
final class SpecializableEncoderTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorDefault(): void
|
||||
{
|
||||
$encoder = new class () extends SpecializableEncoder
|
||||
{
|
||||
};
|
||||
|
||||
$this->assertEquals(75, $encoder->quality);
|
||||
}
|
||||
|
||||
public function testConstructorList(): void
|
||||
{
|
||||
$encoder = new class (1) extends SpecializableEncoder
|
||||
{
|
||||
};
|
||||
|
||||
$this->assertEquals(1, $encoder->quality);
|
||||
}
|
||||
|
||||
public function testConstructorNamed(): void
|
||||
{
|
||||
$encoder = new class (quality: 1) extends SpecializableEncoder
|
||||
{
|
||||
};
|
||||
|
||||
$this->assertEquals(1, $encoder->quality);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$encoder = Mockery::mock(SpecializableEncoder::class)->makePartial();
|
||||
$image = Mockery::mock(ImageInterface::class);
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$image->shouldReceive('encode')->andReturn($encoded);
|
||||
|
||||
$result = $encoder->encode($image);
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user