1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 09:52:59 +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,24 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use Intervention\Image\Drivers\Gd\Decoders\AbstractDecoder;
use Intervention\Image\Tests\BaseTestCase;
use Mockery;
final class AbstractDecoderTest extends BaseTestCase
{
public function testGetMediaTypeFromFilePath(): void
{
$decoder = Mockery::mock(AbstractDecoder::class)->makePartial();
$this->assertEquals('image/jpeg', $decoder->getMediaTypeByFilePath($this->getTestImagePath('test.jpg')));
}
public function testGetMediaTypeFromFileBinary(): void
{
$decoder = Mockery::mock(AbstractDecoder::class)->makePartial();
$this->assertEquals('image/jpeg', $decoder->getMediaTypeByBinary($this->getTestImageData('test.jpg')));
}
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\Base64ImageDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\Base64ImageDecoder::class)]
final class Base64ImageDecoderTest extends BaseTestCase
{
protected Base64ImageDecoder $decoder;
protected function setUp(): void
{
$this->decoder = new Base64ImageDecoder();
}
public function testDecode(): void
{
$result = $this->decoder->decode(
base64_encode($this->getTestImageData('blue.gif'))
);
$this->assertInstanceOf(Image::class, $result);
}
public function testDecoderInvalid(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode('test');
}
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\BinaryImageDecoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\BinaryImageDecoder::class)]
final class BinaryImageDecoderTest extends BaseTestCase
{
public function testDecodePng(): void
{
$decoder = new BinaryImageDecoder();
$image = $decoder->decode(file_get_contents($this->getTestImagePath('tile.png')));
$this->assertInstanceOf(Image::class, $image);
$this->assertEquals(16, $image->width());
$this->assertEquals(16, $image->height());
$this->assertCount(1, $image);
}
public function testDecodeGif(): void
{
$decoder = new BinaryImageDecoder();
$image = $decoder->decode(file_get_contents($this->getTestImagePath('red.gif')));
$this->assertInstanceOf(Image::class, $image);
$this->assertEquals(16, $image->width());
$this->assertEquals(16, $image->height());
$this->assertCount(1, $image);
}
public function testDecodeAnimatedGif(): void
{
$decoder = new BinaryImageDecoder();
$image = $decoder->decode(file_get_contents($this->getTestImagePath('cats.gif')));
$this->assertInstanceOf(Image::class, $image);
$this->assertEquals(75, $image->width());
$this->assertEquals(50, $image->height());
$this->assertCount(4, $image);
}
public function testDecodeJpegWithExif(): void
{
$decoder = new BinaryImageDecoder();
$image = $decoder->decode(file_get_contents($this->getTestImagePath('exif.jpg')));
$this->assertInstanceOf(Image::class, $image);
$this->assertEquals(16, $image->width());
$this->assertEquals(16, $image->height());
$this->assertCount(1, $image);
$this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist'));
}
}

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\DataUriImageDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use stdClass;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\DataUriImageDecoder::class)]
final class DataUriImageDecoderTest extends BaseTestCase
{
protected DataUriImageDecoder $decoder;
protected function setUp(): void
{
$this->decoder = new DataUriImageDecoder();
}
public function testDecode(): void
{
$result = $this->decoder->decode(
sprintf('data:image/jpeg;base64,%s', base64_encode($this->getTestImageData('blue.gif')))
);
$this->assertInstanceOf(Image::class, $result);
}
public function testDecoderNonString(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode(new stdClass());
}
public function testDecoderInvalid(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode('invalid');
}
public function testDecoderNonImage(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode('data:text/plain;charset=utf-8,test');
}
}

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use stdClass;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder::class)]
final class FilePathImageDecoderTest extends BaseTestCase
{
protected FilePathImageDecoder $decoder;
protected function setUp(): void
{
$this->decoder = new FilePathImageDecoder();
}
public function testDecode(): void
{
$result = $this->decoder->decode(
$this->getTestImagePath()
);
$this->assertInstanceOf(Image::class, $result);
}
public function testDecoderNonString(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode(new stdClass());
}
public function testDecoderNoPath(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode('no-path');
}
public function testDecoderTooLongPath(): void
{
$this->expectException(DecoderException::class);
$this->decoder->decode(str_repeat('x', PHP_MAXPATHLEN + 1));
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\FilePointerImageDecoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\FilePointerImageDecoder::class)]
final class FilePointerImageDecoderTest extends BaseTestCase
{
use CanCreateGdTestImage;
public function testDecode(): void
{
$decoder = new FilePointerImageDecoder();
$fp = fopen($this->getTestImagePath('test.jpg'), 'r');
$result = $decoder->decode($fp);
$this->assertInstanceOf(Image::class, $result);
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\ImageObjectDecoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\ImageObjectDecoder::class)]
final class ImageObjectDecoderTest extends BaseTestCase
{
use CanCreateGdTestImage;
public function testDecode(): void
{
$decoder = new ImageObjectDecoder();
$result = $decoder->decode($this->readTestImage('blue.gif'));
$this->assertInstanceOf(Image::class, $result);
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Drivers\Gd\Decoders\SplFileInfoImageDecoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use SplFileInfo;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Drivers\Gd\Decoders\SplFileInfoImageDecoder::class)]
final class SplFileInfoImageDecoderTest extends BaseTestCase
{
public function testDecode(): void
{
$decoder = new SplFileInfoImageDecoder();
$result = $decoder->decode(
new SplFileInfo($this->getTestImagePath('blue.gif'))
);
$this->assertInstanceOf(Image::class, $result);
}
}